Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  59] [ 6]  / answers: 1 / hits: 17910  / 11 Years ago, tue, august 13, 2013, 12:00:00

I'm interested to find out why i always have to do this



$scope.$watch( function() {
return $scope.someData;
}, function( value ) {
console.log( value );
});


for angular to actually watch the data, why do I have to do this, this is one of the things that really bug me because it looks pointless.



If I do something like this



$scope.$watch($scope.someData, function( value ) {
console.log( value );
});


Which is nicer, it never works?



I also use this a lot with factories



say that $data is a factory I have to do



$scope.$watch( function() {
return $data.someData;
}, function( value ) {
console.log( value );
});

More From » angularjs

 Answers
48

This works:



$scope.$watch(someData, function( value ) {
console.log( value );
});

[#76375] Monday, August 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madelyn

Total Points: 449
Total Questions: 100
Total Answers: 100

Location: Seychelles
Member since Fri, May 7, 2021
3 Years ago
madelyn questions
Wed, Jul 28, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
Sat, Nov 7, 20, 00:00, 4 Years ago
Thu, Sep 3, 20, 00:00, 4 Years ago
;