是否可以在同一$watch
内观看多个$ scope值,而不使用ng-repeat? Fiddle
<div ng-app="myapp">
<div ng-controller="ctrlParent">
<input type="checkbox" ng-model="prov1">
<input type="checkbox" ng-model="prov2">
<div>{{prov1}}</div>
<div>{{prov2}}</div>
</div>
</div>
var app = angular.module('myapp', []);
app.controller('ctrlParent', function ($scope) {
$scope.prov1 = true;
$scope.prov2 = true;
$scope.ids = {};
$scope.$watch('prov1', function (newValue, oldValue) {
if (newValue != oldValue) {
console.log("wee");
}
});
});
答案 0 :(得分:0)
从角度1.3开始,您可以使用$scope.$watchGroup
,如下所示:
$scope.$watchGroup(['prov1', 'prov2'], function (newValue, oldValue) {
if (newValue != oldValue) {
console.log("wee");
}
});