-1

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..

1 Answers1

1

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

... ng-click="myControllerMethod(x.vaknaam)">Ga verder</button>
Blue
  • 22,608
  • 7
  • 62
  • 92
  • i didnt use {{ or }} but it still doesnt pass the value. –  Aug 13 '16 at 09:25
  • What happens when you `console.log(vaknaam)`? undefined? – Blue Aug 13 '16 at 09:27
  • I recommend creating a [mcve]. [This post](http://stackoverflow.com/questions/16881478/how-to-call-a-method-defined-in-an-angularjs-directive) may also give you some direction. – Blue Aug 13 '16 at 09:29
  • it gives the right name when i do console.log(vaknaam) but it still doesn't show the div –  Aug 13 '16 at 09:31
  • `vakken.selected == x.vaknaam`? You're setting when you use one equal sign. – Blue Aug 13 '16 at 09:36
  • wow, yeah that's it! thank you very much!! been lookin at this for quite a while can't believe i didn't notice that –  Aug 13 '16 at 09:38
  • Don't feel bad. It took me 6 hours one day to figure out a `;` (semi-colon) was in the correct place. – Blue Aug 13 '16 at 09:39