完成 ng-include 在 angular js 中的加载 [英] Finished Loading of ng-include in angular js

查看:26
本文介绍了完成 ng-include 在 angular js 中的加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng–include 检测 html 加载结束的最佳方法是什么?我想写一些在加载完成后运行的代码.

What is the best way to detect the end of html loading by ng–include? I want to write some code that runs when it has finished loading.

推荐答案

有两种方法可以检测 ng-include 何时完成加载,具体取决于您的需要:

There are two ways to detect when ng-include finished loading, depending on your need:

1) 通过 onload 属性 - 用于内联表达式.例如:

1) via onload attribute - for inline expressions. Ex:

<div ng-include="'template.html'" onload="loaded = true"></div>

2) 通过一个事件 $includeContentLoadedng-include 发出 - 用于应用程序范围的处理.例如:

2) via an event $includeContentLoaded that ng-include emits - for app-wide handling. Ex:

app.run(function($rootScope){
  $rootScope.$on("$includeContentLoaded", function(event, templateName){
     //...
  });
});

当它完成加载内容

这篇关于完成 ng-include 在 angular js 中的加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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