如何添加NG-包括回调到多个NG-包括角JS指令 [英] how to add ng-include callback to multiple ng-include directives in angular js

查看:157
本文介绍了如何添加NG-包括回调到多个NG-包括角JS指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的HTML像这样

I have my HTML like this

  <form ng-controller="testCtrl1">
    <div ng-include="'test/views/navigationbar.html'"></div>
    <div ng-include="'test/views/processnav.html'"></div>
    <div ng-include="'test/views/leftprocesstabs.html'"></div>
   </div>
</form>

我想写通用的方法来检查我的NG-包含文件被加载。

I want to write generalized method to check all my ng-include file are loaded.

加载所有的文件后,我需要做一个服务器的呼叫。

After loading all file i need to make a server call.

有没有办法在JS的角度来检查呢?

Is there any way to check this in angular js?

推荐答案

使用每个模板的onload和递增计数器。
如果表单只包含NG-包括的div,使用beow code得到计数,或者写一个函数来获取的div与NG-包括计数。

use the onload of each template and increment a counter. if the form contains only ng-include divs, use the beow code to get the count, or write a function to get the count of divs with ng-include.

HTML

<form ng-controller="testCtrl1" id="includes">
    <div ng-include="'test/views/navigationbar.html'"  onload="load()"></div>
    <div ng-include="'test/views/processnav.html'" onload="load()"></div>
    <div ng-include="'test/views/leftprocesstabs.html'" onload="load()"></div>
   </div>
</form>

的JavaScript

Javascript

var templates = 0;
var length = $("#includes > div").length; 
$scope.load = function(){
    templates++;
    if(templates >= length){
        onLoadComplete()
    }

}
function onLoadComplete(){
    // all templates are loaded
}

这篇关于如何添加NG-包括回调到多个NG-包括角JS指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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