[英]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. 听起来,Angular的$watch
函数无法观察到包含冒号等字符的string
。
Here's my plunker reproducing the case (console printing the error when the html page opens): http://plnkr.co/edit/w9ItkHZmy4khzYcWHD2A 这是我的小伙子重现的情况(在打开html页面时控制台打印错误): http : //plnkr.co/edit/w9ItkHZmy4khzYcWHD2A
How to deal with this issue? 该如何处理?
You should use $watch
with a string that represents a property in your scope, and not an actually object. 您应该将$watch
与代表范围内的属性而不是实际对象的字符串一起使用。
Just change the $watch
to this: 只需将$watch
更改为此:
$scope.$watch('myHourString', function (hour) {
console.log("im ok now");
angular.noop();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.