같이, 기능 또는 사용 $의 watchCollection에 문자열 바꾸기 :
를 VAR 사용 :
angular.module('TestApp', [])
.controller('MainCtrl', function($scope){
// Object
var settings = {
number: 1,
foobar: 'Hello World'
};
$scope.$watch(function(){ return settings.number; }, function(newValue, oldValue){
console.log('New value detected in settins.number');
});
$scope.$watchCollection(function(){ return settings; }, function(newValue, oldValue){
console.log('New value detected in settings');
});
});
사용 $ 범위 :
angular.module('TestApp', [])
.controller('MainCtrl', function($scope){
// Object
$scope.settings = {
number: 1,
foobar: 'Hello World'
};
$scope.$watch('settings.number', function(newValue, oldValue){
console.log('New value detected in $scope.settings.number');
});
});
예 : http://jsfiddle.net/Chofoteddy/2SNFG/
를
* 참고 : AngularJS 버전 1.1.x 이상에서 사용할 수있는 $ watchCollection. 객체의 배열이나 여러 속성에서 여러 값을보아야하는 경우에 유용합니다.
를 방문 나는 아이들이 내 변화가 변화를 유발하지 않는 생각합니다. 수 자체를보고, 부모 개체에 포함하는 대신 번호를 업데이트 해 볼 수 있습니까? 잘 모르겠지만 구버젼의 이전 버전에서 같은 문제가 발생했습니다 – Anoop