Mik378
Mik378

Reputation: 22171

AngularJS / $watch can't observe any string

It sounds that a string containing some characters like a colon can't be observed by angular's $watch function.

Here's my plunker reproducing the case (console printing the error when the html page opens): http://plnkr.co/edit/w9ItkHZmy4khzYcWHD2A

How to deal with this issue?

Upvotes: 2

Views: 80

Answers (2)

D.Evangelista
D.Evangelista

Reputation: 6543

You should use $watch with a string that represents a property in your scope, and not an actually object.

Just change the $watch to this:

$scope.$watch('myHourString', function (hour) {
    console.log("im ok now");
    angular.noop();
});

Upvotes: 3

Nicolas ABRIC
Nicolas ABRIC

Reputation: 4935

Try with this :

$scope.$watch('myHourString', function (hour) {
  angular.noop();
});

See working plunker here

Upvotes: 1

Related Questions