简体   繁体   English

跳过$观看初次通话

[英]Skip $watch initial call

So apologies in advance for the terrible title. 因此,为可怕的头衔提前道歉。 I don't really know all the correct angular terminology for these things. 我真的不知道这些东西的所有正确的角度术语。

I have code like this in a scope: 我在范围内有这样的代码:

$scope.catName = 'Le cat'

//<-- Magic goes here

$scope.$watch('catName', function () {
    //[...]
})

Now since angular waits until the next digest (is that the correct term?) to evaluate the watch, my initial assignment ('Le cat') will trigger the watch. 现在,由于角度等到下一个摘要(正确的术语?)来评估手表,我的初始分配('Le cat')将触发手表。

I would like this assigment to not trigger the watch, but changes after this to do so. 我希望这个配置不会触发手表,但在此之后更改会这样做。

Is there some way to reset the 'dirty state' of catName? 有没有办法重置catName的'脏状态'?

Js-fiddle: http://jsfiddle.net/7DNrD/1/ Js-fiddle: http//jsfiddle.net/7DNrD/1/

Check this workaround 检查此解决方法

http://jsfiddle.net/7DNrD/5/ http://jsfiddle.net/7DNrD/5/

$scope.catName = 'Le cat'

$scope.$watch('catName', function (newValue, oldValue) {
    if(oldValue === newValue){
        return;
    }
    //[...]
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM