示例场景,
伪代码
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
?
答案 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
});