Javascript 在嵌套的 ng-repeat 中时,AngularJS ng-click 事件不会触发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14520774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 17:04:10  来源:igfitidea点击:

AngularJS ng-click event is not firing when inside nested ng-repeat

javascriptonclickangularjsangularjs-ng-repeat

提问by miru87

I have problem with ng-click (I'm using angular 1.0.4). First ng-click works but second no.

我有 ng-click 问题(我使用的是 angular 1.0.4)。第一次 ng-click 有效,但第二次无效。

    <div class="menu-group" ng-repeat="module in modules">
         <div ng-click="toggle($event, $parent)" class="group-head">{{module.group.name}} <span class="{{module.group.icon}}"></span></div>
         <ul class="menu collapsed" ng-init="items = module.group.items">
              <li ng-repeat="item in items" ng-click="openCategory($event, '{{item.name}}')">{{item.display}}</li>
         </ul>
    </div>

Generated code looks good:

生成的代码看起来不错:

    <li ng-repeat="item in items" ng-click="openCategory($event, 'simpleName')" class="ng-scope ng-binding">Simple name</li>

回答by SunnyShah

Instead of '{{item.name}}'just use item.name

而不是'{{item.name}}'仅仅使用item.name

Demo: http://plnkr.co/edit/QNKZDT9N5k2tQaRrFlwY?p=preview

演示:http: //plnkr.co/edit/QNKZDT9N5k2tQaRrFlwY?p=preview