santhosh
santhosh

Reputation: 2008

is there any differences between $scope.$watch and $watch?

I was learning angular. i didn't get anyhitng from angular documentation can anyone please tell me what is $watch

what does it happens if we change that to $scope.$watch

sorry i'm new to the anguar this question seem like bit silly....if i'm wrong in knowledge

Upvotes: 3

Views: 103

Answers (2)

muffel
muffel

Reputation: 7360

if you watch an expression, you need a context that is used to resolve it. Consider

$watch("foo", handler);

how should angular know what foo to watch? It makes only sense in the context of a scope

somescope.$watch("foo", handler);

so angular know what foo to watch.

But if you are talking about watches in general, many people omit the scope for the sake of simplicity. But you should know: You can't watch for something if you don't know where to watch ;)

Upvotes: 1

There is not stand alone $watch service. People are saying $watch instead of $scope.$watch but it's the same. it's just longer to say $scope.$watch, and it's just to mention that even if it's related to $scope he's like a whole new service.

But I may be wrong there's maybe an external stand alone service who's name is $watch, but I don't think so.

Upvotes: 2

Related Questions