2016-02-05 21 views
0

比如我有

$scope.array = [{ foo: 'bar'}, { foo: 'bar2'}] 

我想看這個陣列,使得

$scope.array.pop(); //$watch is not called 
$scope.array[0].foo = 'newbar'; //$watch is called 
$scope.array = [{ foo: 'bar' }, { foo: 'anotherbar' }]; //$watch is not called 

是否有可能與$做到這一點範圍。$看?

回答

0

您可以使用函數返回所需的值看:

$scope.$watch(function(scope) { return scope.array && scope.array[0].foo; }, function(newValue, oldValue) { 
    // any action here 
    } 
); 

,如果你需要觀察更多的itens,你可以返回另一個數組所有Foo的對象,例如。

相關問題