1) 是否有任何摘要完成事件可用于更新我的 Canvas 。我有一个 Angular 应用程序,它可以查看 Canvas 对象的不同属性。每当我更改属性时,一旦摘要完成,如果我可以获得摘要完成事件,我就可以更新 Canvas (使用 kineticJs)以使用最新属性重绘图表。
目前我正在从 View 中调用一个方法
2) 只要打开对象设置,我只是使用 View 并将其路由到新 View 。在这种情况下,url 也会随着网页/#view 的变化而变化。它只是弹出窗口,我不需要页面末尾的#view,但仍然使用路由和 View 概念。有没有别的办法。
最佳答案
更新
Karl seamon 在 ng-conf 2014 发表演讲.
在此video (22:20 分钟)他谈到了内置 $postDigestWatch 的 future 可能性。
这是一个悬而未决的问题:https://github.com/angular/angular.js/issues/5828
所以,它可能会在未来的版本中进入核心,在那之前你可以使用下面的技巧。
一个example on plunker .
- 一个摘要循环可能有多个
$digest
。 - 我
$watch
为第一个$digest
注册了一个$timeout
,它将在摘要周期结束后运行。 - 我必须立即取消注册
$watch
,以避免一个摘要周期内出现多个$timeout
回调。 - 在
$timeout
回调中,我调用了 user callback 并为下一个$digest
注册了一个$watch
>.
将 $watch 与 $timeout 结合使用:
function postDigest(callback){
var unregister = $rootScope.$watch(function(){
unregister();
$timeout(function(){
callback();
postDigest(callback);
},0,false);
});
}
postDigest(function(){
console.log('do something');
})
$digest ,来自 docs :
If you want to be notified whenever $digest() is called, you can register a watchExpression function with $watch() with no listener.
$timeout ,从这里开始:Defer angularjs watch execution after $digest (raising DOM event)
$timeout will cause another digest cycle to be executed after the function is executed. If your trigger does not affect anything Angular, you can set the invokeApply argument to false to avoid running another digest cycle.
关于javascript - Angular JS 识别摘要完成事件并在 View 更改期间从 angular js 中的 url 中删除#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21138388/