ng-repeat inside ul - impossible to bind function

350 views
Skip to first unread message

Dmitry

unread,
Sep 18, 2012, 8:53:23 AM9/18/12
to ang...@googlegroups.com
Hi
I have strange issue with list and ng-repeat.

this is small jsfiddle to explain the problem;  http://jsfiddle.net/dmitrysh/8LcwJ/

I have a list which I output with ng-repeat:
<li ng-repeat="item in Arr">
  <a href="{{item}}" ng-click="do($event, '{{item}}')">{{item}}</a>
</li>

I would like to implement the following:

when user click on link - do() will be executed, but right now  page reload as with normal link, without executing do() . (I've tried $event.preventDefault(); too)

I've tried to bind with jQuery - same problem. Once I looked into html code, link looks like this: 
<li ng-repeat="item in Arr" class="ng-scope">
    <a ng-click="do($event, 'aa');" href="aa" class="ng-binding">aa</a>
</li>

looks like function is not get executed. Maybe ng-binding prevent this?

If I empty href="" - nothing happened.

Could someone help me understand this behavior, I just need an Ajax call on user press on link.


Thank you

James Wright

unread,
Sep 18, 2012, 10:08:23 AM9/18/12
to ang...@googlegroups.com

Dmitry

unread,
Sep 18, 2012, 4:06:50 PM9/18/12
to ang...@googlegroups.com
Hi James, 
Thank you very much.

I surprised why there are no warnings were shown?  

Andy Joslin

unread,
Sep 18, 2012, 7:05:57 PM9/18/12
to ang...@googlegroups.com
Hi Dmitry, 

Well, why would angular error?  You technically just passed a string into the 'do' function:  do($event, '{{item}}')
Reply all
Reply to author
Forward
0 new messages