1)是否有任何摘要完成事件,我可以用它来更新我的画布。我有一个角度应用程序,它具有画布对象的不同属性的视图。每当我更改属性时,一旦摘要完成,如果我可以获得摘要完成事件,我可以更新画布(使用kineticJs)重绘具有最新属性的图表。
目前我正在从视图中调用方法
2)我只是在打开对象设置时使用视图并将其路由到新视图。在这种情况下,网址也随着网页/ #view而改变。它只是弹出窗口,我不需要页面末尾的#view,但仍然使用路由和视图概念。还有别的吗?
Karl seamon在ng-conf 2014发表了演讲。
在这个video(22:20分钟),他谈到了内置$ postDigestWatch的未来可能性。
这是一个未解决的问题:https://github.com/angular/angular.js/issues/5828
所以,它可能会在未来的版本中找到核心,直到那时你可以使用下面的技巧。
$digest
。$watch
为第一个$digest
注册了一个$timeout
,它将在消化周期结束后运行。$watch
以避免一个摘要周期的多个$timeout
回调。$timeout
回调中,我调用用户回调并为下一个$watch
注册$digest
。function postDigest(callback){
var unregister = $rootScope.$watch(function(){
unregister();
$timeout(function(){
callback();
postDigest(callback);
},0,false);
});
}
postDigest(function(){
console.log('do something');
})
$ digest,来自docs:
如果您希望在调用$ digest()时收到通知,则可以使用$ watch()注册watchExpression函数而不使用侦听器。
$ timeout,从这里:Defer angularjs watch execution after $digest (raising DOM event)
$ timeout将导致在执行函数后执行另一个摘要循环。如果您的触发器不影响任何Angular,您可以将invokeApply参数设置为false以避免运行另一个摘要周期。
作为Ilan所说的替代方案,你可以使用$ evalAsync。
来自同一个docs:
Executes the expression on the current scope at a later point in time.
The $evalAsync makes no guarantees as to when the expression will be executed, only that:
it will execute after the function that scheduled the evaluation (preferably before DOM rendering).
at least one $digest cycle will be performed after expression execution.
Any exceptions from the execution of the expression are forwarded to the $exceptionHandler service.
Note: if this function is called outside of a $digest cycle, a new $digest cycle will be scheduled. However, it is encouraged to always call code that changes the model from within an $apply call. That includes code evaluated via $evalAsync
另外,请看一下this comment