AngularJS ng-click event not firing within ng-repeat

て烟熏妆下的殇ゞ 提交于 2019-12-11 09:47:49

问题


I have a list of tags built from a JSON object...

<div ng-repeat="comedian in comedians.details | orderBy: 'tag' | unique: 'tag'">
    <span ng-click="search = { tag: comedian.tag }">{{ comedian.tag }}</span>
</div>

And a list of images built from the same object...

<div ng-repeat="comedian in comedians.details | orderBy: 'name' | filter:search:strict">
    <img width="50" src="{{ comedian.image }}" alt="{{ comedian.name }}">
</div>

Both lists build as expected. But the click event is not firing to filter the images. If I manually build the list of tags like below the click event works...

<span ng-click="search = { tag: 'Character'}">Character</span>
<span ng-click="search = { tag: 'Sitcom'}">Sitcom</span>

But inside the ng-repeat they do not. Let me know if you need any other details! Thanks


回答1:


Like @Cherniv suggested in the first comment: use $parent.search so assing to the parent scope.

I'm mostly adding this as an answer so it can be accepted, since this question looks pretty unanswered at first sight, while it's actually solved.



来源:https://stackoverflow.com/questions/19358798/angularjs-ng-click-event-not-firing-within-ng-repeat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!