Stig Vanbrabant Stig Vanbrabant - 3 months ago 27
AngularJS Question

Angular: Can't use value of ng-repeat in ng-click

I want to have a div show up when clicked on the title, to do this i wanted to pass the value of the ng-repeat in the ng-click. But for some reason it doesn't get it through.

Here's the code of my list:

<ul id="vak_lijst">

<li ng-repeat="x in vakken.vakken | unique:'vaknaam'" ng-click="vakken.setSelected(x.vaknaam)">

<span>{{ x.vaknaam }}</span>

<div ng-show="vakken.selected = x.vaknaam">

// some content

</div>

</li>

</ul>


Here's my script:

vakken.setSelected = function(vaknaam) {
vakken.selected = vaknaam;
console.log('clicked');
}


Excuse me that some names are in dutch..

Answer

You don't need {{ or }} to access variables inside the ng-click:

... ng-click="myControllerMethod(x.vaknaam)">Ga verder</button>
Comments