【问题标题】:How to determine when AngularJS has finished rendering all of the components & directives如何确定 AngularJS 何时完成渲染所有组件和指令
【发布时间】:2016-12-23 19:39:15
【问题描述】:

当 AngularJS 完成所有路由、组件和指令的渲染后,有什么方法可以运行脚本吗?

例如,当所有带有 templateURL 的组件和指令都完成渲染时。

【问题讨论】:

    标签: angularjs domready angular-component-router angular-components


    【解决方案1】:

    $timeout 是在 DOM 完成渲染后需要执行某些操作时的最佳方式:

    $timeout(function() {
    
    });
    

    http://lorenzmerdian.blogspot.de/2013/03/how-to-handle-dom-updates-in-angularjs.html

    【讨论】:

      【解决方案2】:

      请使用$timeout服务,延迟为0ms:

      $timeout(function() {
         //this code will be invoked when all directives and components will be rendered
      });
      

      【讨论】:

        【解决方案3】:

        如果是出于显示目的,您可以使用ngCloak 指令。

        根据 Angular 文档,它用于防止 Angular html 模板在您的应用程序加载时被浏览器以原始(未编译)形式短暂显示。使用该指令可以避免 html 模板显示引起的不良闪烁效果。

        您也可以使用$http.pendingRequests

        【讨论】:

          猜你喜欢
          • 2017-02-04
          • 2012-12-23
          • 1970-01-01
          • 2017-10-30
          • 1970-01-01
          • 2013-06-14
          • 2012-08-27
          • 1970-01-01
          • 2023-03-17
          相关资源
          最近更新 更多