$ evalAsync之后是否可以阻止另一个$ digest?

时间:2014-02-19 10:10:47

标签: angularjs

示例场景,

伪代码

scope.set_value ( user_input ) { 

    scope.value = user_input;

    // trigger digest : evaluation of several validators

    // execute after digest and prior to DOM rendering
    scope.$evalAsync(function() {

        // check if the value is valid based on 
        // validators calculated during the last digest

        if ( !scope.is_valid() )
            // trigger another digest with null value
            scope.value = null;

        else
            // NO CHANGE
            // prevent another digest... is it possible ? 

    });

不考虑此处可能出现的无限循环 - 是否可以取消$digest中的下一个$evalAsync

1 个答案:

答案 0 :(得分:0)

以供将来参考我将回答我自己的问题....可以用$$postDigest

来实现
scope.set_value ( user_input ) { 

    scope.value = user_input;

    // trigger digest : evaluation of several validators

    // execute after digest and prior to DOM rendering
    scope.$$postDigest(function() {

        // check if the value is valid based on 
        // validators calculated during the last digest

        if ( !scope.is_valid() )
            // trigger another digest with null value
            scope.$apply( function () {  scope.value = null; });

        // NO CHANGE
    }); 
相关问题