3 回答

TA貢獻(xiàn)1789條經(jīng)驗 獲得超10個贊
從AngularJS 1.1.4開始,您可以使用$watchCollection:
$scope.$watchCollection('[item1, item2]', function(newValues, oldValues){
// do stuff here
// newValues and oldValues contain the new and respectively old value
// of the observed collection array
});

TA貢獻(xiàn)1869條經(jīng)驗 獲得超4個贊
$watch 第一個參數(shù)也可以是一個函數(shù)。
$scope.$watch(function watchBothItems() {
return itemsCombinedValue();
}, function whenItemsChange() {
//stuff
});
如果您的兩個組合值很簡單,則第一個參數(shù)通常只是一個角度表達(dá)式。例如,firstName和lastName:
$scope.$watch('firstName + lastName', function() {
//stuff
});
添加回答
舉報