Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angular js中向多个ng include指令添加ng include回调_Javascript_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Javascript 如何在angular js中向多个ng include指令添加ng include回调

Javascript 如何在angular js中向多个ng include指令添加ng include回调,javascript,angularjs,angularjs-directive,angularjs-scope,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,我的HTML是这样的 <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.htm

我的HTML是这样的

  <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包含文件是否被加载

加载所有文件后,我需要进行服务器调用


有没有办法在angular js中检查这一点

ng include
触发通过模板缓存的请求。这是异步完成的,因此不,angular无法为您提供所有模板加载完成时的触发器

您可以将模板预回迁到缓存中,并从此处处理事件

比如说,

// inject $q, $http, $templateCache to your controller 
...
var promises = [];
promises.push($http.get('test/views/navigationbar.html',{ cache : $templateCache }));
promises.push($http.get('test/views/processnav.html',{ cache : $templateCache }));
promises.push($http.get('test/views/leftprocesstabs.html',{ cache : $templateCache }));
$q.all(promises, function (data) { 
 console.log('All templates are loaded into the cache !');
});
...

ng include
触发通过模板缓存的请求。这是异步完成的,因此不,angular无法为您提供所有模板加载完成时的触发器

您可以将模板预回迁到缓存中,并从此处处理事件

比如说,

// inject $q, $http, $templateCache to your controller 
...
var promises = [];
promises.push($http.get('test/views/navigationbar.html',{ cache : $templateCache }));
promises.push($http.get('test/views/processnav.html',{ cache : $templateCache }));
promises.push($http.get('test/views/leftprocesstabs.html',{ cache : $templateCache }));
$q.all(promises, function (data) { 
 console.log('All templates are loaded into the cache !');
});
...

使用每个模板的onload并递增一个计数器。 如果表单仅包含ng include div,请使用beow代码获取计数,或编写函数获取包含ng include的div计数

HTML


使用每个模板的onload并递增一个计数器。 如果表单仅包含ng include div,请使用beow代码获取计数,或编写函数获取包含ng include的div计数

HTML


这不是一般的BCU ng include可能不是3始终使用代码进行div计数,假设表单中的所有div都是ng include div..这需要jquery?是的,这需要jquery,但您可以通过许多其他方式获得计数。这不是一般化的BCU ng include可能不是3始终使用代码进行div计数,假设表单中的所有div都是ng include div..这需要jquery?是的,这需要jquery,但是有很多其他方法可以获得计数。谢谢,我添加了这个。无法打印
console.log('所有模板都加载到缓存中!')谢谢,我添加了这个。无法打印
console.log('所有模板都加载到缓存中!')
var templates = 0;
var length = $("#includes > div").length; 
$scope.load = function(){
    templates++;
    if(templates >= length){
        onLoadComplete()
    }

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