angularjs - ng-mouseenter 在 ng-repeat 中不起作用

标签 angularjs ng-repeat

ng-mouseenter 在我的 ng-repeat 中不起作用,它只在它之外起作用。你能解释一下这里发生了什么吗? http://plnkr.co/edit/BklqI09raI18RAaqmca2?p=preview

<p ng-repeat="i in [1,2]" ng-init="n=0">
<span ng-mouseenter="n = n + 1">ng-repeat {{i}}</span>
</p>
<p><span ng-mouseenter="n = n + 1">Outside the repeat</span></p>
<pre>n : {{n}}</pre>

最佳答案

当您使用 ng-repeat 时,会在其中创建一个作用域。如果要在父作用域中打印 n,请在 ng-repeat 中使用 $parent 修改父作用域: ng-mouseenter="$parent.n = $parent.n + 1"

关于angularjs - ng-mouseenter 在 ng-repeat 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25835336/

相关文章:

javascript - 使用 NG-repeat 制作带有多个单选按钮的表单 : want to reset the value of all the radio buttons

javascript - 使用 Angular 和 JSON 避免再次调用 API

html - 将最小值设置为减法 (AngularJS)

angularjs - $index of ng 在 angularjs 指令中重复

angularjs - 自动为所有 ng-repeat 行选择单选按钮

angularjs - 当数组中的对象列表时,ng-repeat 中不允许出现重复错误

javascript - AngularJS 中的可编辑表格单元格

javascript - 如何通过 Gulp 任务增加版本号?

javascript - 从 api 中解析 php 中的 json 数组

javascript - 带有禁用输入的 Angular 引导日期选择器弹出窗口