角JS识别viewchange期间角度JS的消化从URL完成事件和删除# [英] Angular JS identify an digest complete event and removing # from url in angular js during viewchange

查看:210
本文介绍了角JS识别viewchange期间角度JS的消化从URL完成事件和删除#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)是否有任何消化的,我可以用它来更新我的画布上完成事件。我有一个角度的应用程序有鉴于画布对象的不同属性。每当我更改属性,一旦消化完成后,如果我能得到完全消化的事件,我可以更新(使用kineticJs)画布重绘与最新的性能图表。

1) Is there any digest complete event which I can use to update my canvas. I have an angular app which has view for different properties of the canvas object. Whenever I change the property, once the digest is complete, If I can get the digest complete event I can update the canvas(using kineticJs) to redraw the chart with latest properties.

目前我正在从视图中调用一个方法

Currently i am calling a method from the view

2)我只是用视图和路由到只要对象设置打开一个新视图。在这种情况下,URL也与网页/#view.Its只是我不需要的#view在页面的结束,但仍然使用路由和视图概念弹出更改。是否有任何otherway。

2) I am just using views and routing it to a new view whenever an object settings is opened. In this case the url also change with the webpage/#view.Its just the popup I dont need the #view at the end of the page but to still use the routing and view concept. Is there any otherway.

推荐答案

卡尔seamon了在 NG-conf的谈话2014年

Update

Karl seamon gave a talk in ng-conf 2014.

在此影片 22:20分),他谈到了未来的方法可行内置的 $ postDigestWatch

In this video (22:20 minute) he talked about a future possiblity of a built-in $postDigestWatch.

下面是一个悬而未决的问题:<一href=\"https://github.com/angular/angular.js/issues/5828\">https://github.com/angular/angular.js/issues/5828

Here is an open issue in: https://github.com/angular/angular.js/issues/5828

那么,它可能会得到未来版本中的核心,在此之前,你可以使用下面的把戏。

So, It will probably get to the core in future releases, until then you can use the trick below.


  • 系统消化周期可能有多个 $消化

  • I $观看第一个 $消化来注册 $超时消化周期结束之后将运行。

  • 我必须取消注册为一个 $观看立即以避免多个 $超时回调消化周期。

  • $超时回调我调用用户回调并注册 $观看下一个 $消化

  • A digest cycle may have multiple $digest.
  • I $watch for the first $digest to register a $timeout which would run after the digest cycle ends.
  • I must unregister the $watch immediately to avoid multiple $timeout callbacks for one digest cycle.
  • In the $timeout callback I invoke the user callback and register a $watch for the next $digest.
function postDigest(callback){    
  var unregister = $rootScope.$watch(function(){  
    unregister();
    $timeout(function(){
      callback();
      postDigest(callback);
    },0,false);       
  });
}

postDigest(function(){
  console.log('do something');
})


$摘要,从文档

如果您希望收到通知时的 $摘要()被调用,您可以注册的 $表() watchEx pression功能,没有听众。

If you want to be notified whenever $digest() is called, you can register a watchExpression function with $watch() with no listener.

$超时,从这里:<一href=\"http://stackoverflow.com/questions/16066239/defer-angularjs-watch-execution-after-digest-raising-dom-event\">Defer angularjs手表执行$消化后(提高DOM事件)

$超时会造成执行函数后执行另一个摘要周期。如果您的触发器不影响任何角度,你可以设置invokeApply参数为false,以避免在运行其它消化周期。

$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.

这篇关于角JS识别viewchange期间角度JS的消化从URL完成事件和删除#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆