AngularJS ng include partial在$http拦截器中不可用
AngularJS ng-include partial not available in $http interceptor
我正试图在AngularJS应用程序中加载ajax内容时显示ajax加载gif。
我已经用下面的代码完成了所有工作。我的问题是,我必须在所有页面上复制并粘贴#loadingWidget
标记。我希望能够只包括一部分。我尝试使用ng-include
,但在拦截器运行时,似乎没有加载包含ng的html页面。
有没有其他方法可以包括这个部分,而不必将相同的html标记复制粘贴到每个页面中?
// Module for the rest of the pages
var myapp = angular.module('myapp ', []);
// Set some configs
myapp .config(function($httpProvider) {
// This loads the ajax loading image when necessary
var $http,
interceptor = ['$q', '$injector', function ($q, $injector) {
var error;
function success(response) {
// get $http via $injector because of circular dependency problem
$http = $http || $injector.get('$http');
if($http.pendingRequests.length < 1) {
$('#loadingWidget').hide();
}
return response;
}
function error(response) {
// get $http via $injector because of circular dependency problem
$http = $http || $injector.get('$http');
if($http.pendingRequests.length < 1) {
$('#loadingWidget').hide();
}
return $q.reject(response);
}
return function (promise) {
$('#loadingWidget').show();
return promise.then(success, error);
}
}];
$httpProvider.responseInterceptors.push(interceptor);
});
目前我必须在每一页中包含这个
<div class="modal" id="loadingWidget" style="position:absolute; top: 45%;" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div id="loadingWidget" class="row-fluid ui-corner-all" style="padding: 0 .7em;">
<div class="loadingContent">
<p>
<img alt="Content" src="images/ajax-loading.gif" /> Thinking
</p>
</div>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
我希望能够在我的所有页面中添加这个,但当我添加这个时,什么都不会发生
<ng-include src="loading.html" ></ng-include>
ng-include将执行您想要的操作,但您需要向src-<ng-include src="'loading.html'" ></ng-include>
添加额外的引号
如果这不起作用,请查看浏览器开发工具中的"网络"选项卡,看看它是否真的正确加载了页面,或者是否需要更改路径。路径是相对于主页面的。
相关文章:
- Meteor如何接收HTTP请求
- 在我的情况下,如何进行http请求
- //而不是在src=“”上使用http://"属性
- 我无法使用angularJs($http)访问服务器
- AJAX简单错误.XMLHttpRequest无法加载http://localhost/mpl/getPage.php.
- 如何将PHP get查询转换为Meteor's HTTP.get()
- 角度异步http自动完成
- 什么's本地node.js服务器和python简单http服务器之间的区别
- 角度http服务器页面刷新404s
- http.listen()在运行时接受终端命令
- AngularJS ng include dons'不起作用
- IIS动态HTTP响应标头
- spring和angularJS(我得到了类似HTTP状态404的错误)
- 存储$http如何从$http函数(Angularjs)外部获取可访问变量中的响应
- Typescript angularjs$http获取响应类型(避免使用<any>)
- 如何从HTTP上下文对象中获取Post数据
- 使用插件收听Firefox标签的http请求
- ng include导致角度问题
- "访问控制允许起源”;通过javascript从http页面调用同一网站的httpsurl时出现问题
- AngularJS ng include partial在$http拦截器中不可用