0
我使用angular watch在數組中的值更改時觸發回調函數。該函數然後必須獲取已更改的數組中的值。下面是代碼,並鏈接到小提琴如何使用Angularjs手錶獲取newVal
<div ng-app>
<h2>Please modify the values, how to watch them?</h2>
<div ng-controller="TodoCtrl">
<ul>
<li ng-repeat="col in columns">
<input type="text" ng-model="col.field" />
<input type="text" ng-model="col.displayName" />
</li>
</ul>
</div>
</div>
--------------------------------
function TodoCtrl($scope) {
$scope.columns = [
{ field:'title', displayName: 'TITLE'},
{ field: 'content', displayName: 'CONTENT' }
];
$scope.$watch('columns', function(newVal) {
alert(newVal);
},true);
}
鏈接到小提琴: - http://jsfiddle.net/SYx9b/#&togetherjs=MLzovnvQAI