0

Original question: (please skip to the EDIT)

I am trying to make images of books which I am receiving clickable.

<div ng-app="myApp" ng-controller="myAppCrtl"> 
    <ul ng-repeat="x in browseBooks">
        <div id="{{x.bookId}}">
            <li>        
            <a href="" ng-click=logout()><img style="max-width:100px;" ng-src="{{x.img}}"></a>
                <p>{{x.name}}</p>
                <p>{{x.price}}</p>
                <br>
            </li>   
        </div>
    </ul>
</div>

Following the solutions provided here doesn't work, and the link to the angularjs site is broken.

I know the function logout works perfectly, as with button it is executing. The problem with <a> tag I am unable to make the image trigger a desired function.


EDIT

I understand what my problem is, ng-repeat creates a child scope for each item in the loop. So trying to access the logout() method defined in parent scope is not working. ?

Any idea? even replacing "logout()" with $parent.logout() isn't working...

EDIT2

It is working, however all changes are local to inner scope...

David
  • 33,444
  • 11
  • 80
  • 118
Tony Tannous
  • 14,154
  • 10
  • 50
  • 86

2 Answers2

0

You need quotes around logout()

and then you could use javascript:void(0) if needed and # doesn't work for you

<a href="javascript:void(0)" ng-click="logout()"><img style="max-width:100px;" ng-src="{{x.img}}"></a>
abney317
  • 7,760
  • 6
  • 32
  • 56
0

Have you tried:

   <li ng-click="logout()">        
    <a href="#"><img style="max-width:100px;" ng-src="{{x.img}}"></a>
        <p>{{x.name}}</p>
        <p>{{x.price}}</p>
        <br>
    </li> 
David Anthony Acosta
  • 4,766
  • 1
  • 19
  • 19