我们可以触发$ digest而不使用Angular js中的$ apply吗?

时间:2017-06-30 11:12:36

标签: angularjs scope apply angular-digest

当我经历范围的生命周期时,$digest遇到的$apply应该被$digest调用。但我想知道是否可以在没有$apply的情况下启用function html_entity_decode(message) { var element = document.createElement("div"); element.innerHTML = message; return element.innerHTML; } console.log(html_entity_decode("Some title post text here – some text after dash")); console.log(html_entity_decode("‘Title text in quotes ’: More title text"));。如果是,那么什么是劣势

2 个答案:

答案 0 :(得分:0)

当您调用$scope.$apply()函数时,它会调用$rootScope.$digest()。因此,摘要周期从rootScope开始,并调用所有子范围。

您可以使用$scope.$digest()调用摘要,但这将仅启动子范围的循环。有时绑定不会正确发生,因为摘要周期不是从根范围开始的。

您可以查看this文章,了解摘要周期的工作原理

答案 1 :(得分:0)

$scope.$digest()函数遍历$scope对象中的所有监视及其子$scope个对象(如果有)。当$digest()遍历手表时,它会调用每个手表的值函数。

$scope.$apply()函数将一个函数作为执行的参数,然后在内部调用$scope.$digest()