【发布时间】:2014-06-08 17:53:03
【问题描述】:
我有一个简单的输入列表,绑定到显示良好的项目列表。当我更改输入中的值时,总和不会更新??
示例:http://plnkr.co/edit/B7tEAsXSFvyLRmJ5xcnJ?p=preview
HTML
<body ng-controller="MainCtrl">
<div ng-repeat="item in items">
<p><input type=text value="{{item}}"></p>
</div>
Total: <input type=text value="{{sum(items)}}">
</body>
脚本
app.controller('MainCtrl', function($scope) {
$scope.items = [1,2,5,7];
$scope.sum = function(list) {
var total=0;
angular.forEach(list , function(item){
total+= item;
});
return total;
}
});
【问题讨论】: