我用 ng-repeat 生成了一个列表,其中每个项目都有一个计数变量。在我有一个链接的列表项中,我想在单击它时增加计数。
我不知道用 Angular-JS 的方式解决这个问题。
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js"></script>
<script>
function increment() {
}
</script>
</head>
<body>
<div ng-init="items = [
{name:'fruit', count:4},
{name:'car', count:1},
{name:'dog', count:2}
]">
<ul>
<li ng-repeat="item in items">
<span>Count:</span>
<span>{{item.count}}</span>
<a onclick="increment();">Increment</a>
</li>
</ul>
</div>
</body>
使用 JQuery,我会为 span 分配一个唯一的 id,使用一些计数器变量,将此 id 传递给增量,找到 html 对象并更新。但我很好奇 Angular 的做法。