什么是AngularJS $$阶段? [英] What is $$phase in AngularJS?
问题描述
我发现这个code段是一个角指令有人写了自举模式的一部分。
I found this code snippet which is part of a angular directive someone wrote for bootstrap modal.
//Update the visible value when the dialog is closed
//through UI actions (Ok, cancel, etc.)
element.bind("hide.bs.modal", function () {
scope.modalVisible = false;
if (!scope.$$phase && !scope.$root.$$phase)
scope.$apply();
});
我了解,这部分是针对双向下半年绑定,我们绑定到hide.bs.modal事件和更新模式时,用户界面的变化。
I understood that this part is for the latter half of two way binding we bind to hide.bs.modal event and update modal when UI changes.
我只是想知道为什么这个人打电话申请前检查范围和rootScope $$阶段?
I just wanted to know why is the person checking $$phase for scope and rootScope before calling apply ?
我们不能通俗易懂打电话申请?
Can't we straightaway call apply ?
什么是$$阶段在这里?
What is $$phase here?
我试图寻找了很多,找不到任何很好的解释。
I tried searching a lot, couldn't find any good explanation.
编辑:
我发现在那里我看到的例子:
<一href=\"http://stackoverflow.com/questions/19644405/simple-angular-directive-for-bootstrap-modal\">Simple为引导模态角指令
推荐答案
$$阶段
的同时角度设置的标志是在 $消化
周期
$$phase
is a flag set while angular is in a $digest
cycle.
有时(在少数情况下),你要干什么之前 $适用
$$阶段的范围>。
Sometimes (in rare cases), you want to check $$phase
on the scope before doing an $apply
. An error occurs if you try to $apply
during a $digest
:
错误:$申请已经在进行中
Error: $apply already in progress
这篇关于什么是AngularJS $$阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!