Javascript 如何在angular js中向多个ng include指令添加ng include回调
我的HTML是这样的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
<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
}