Javascript Angular$httpProvider拦截器停止为';ng包括';在加入“后”;“用户界面网格”;到应用程序
我正试图添加到我的应用程序中,遵循介绍教程,并面临以下问题 首先,网格工作,我可以在控制器中创建它并绑定到视图,但是 一旦我将它添加到项目中(只是作为模块添加,而不是在任何地方实际使用它),以前工作过的拦截器就不再启动,更具体地说,它是使用ng include加载视图模板所需的(请参阅下面的一些代码摘录) 编辑:请注意,ng include起作用,它只是不通过拦截器,而是在没有拦截器时起作用Javascript Angular$httpProvider拦截器停止为';ng包括';在加入“后”;“用户界面网格”;到应用程序,javascript,angularjs,angular-ui-grid,ng-grid,Javascript,Angularjs,Angular Ui Grid,Ng Grid,我正试图添加到我的应用程序中,遵循介绍教程,并面临以下问题 首先,网格工作,我可以在控制器中创建它并绑定到视图,但是 一旦我将它添加到项目中(只是作为模块添加,而不是在任何地方实际使用它),以前工作过的拦截器就不再启动,更具体地说,它是使用ng include加载视图模板所需的(请参阅下面的一些代码摘录) 编辑:请注意,ng include起作用,它只是不通过拦截器,而是在没有拦截器时起作用 角度1.4.8 UI网格3.2.1 jQuery 2.2.0 我尝试的是: 使用其他角度版本 已使用
- 角度1.4.8
- UI网格3.2.1
- jQuery 2.2.0
<body>
<div ng-app="app">
<div ng-controller="app.views.layout as vm">
<div ng-include="'/App/Main/views/layout/header.cshtml'"></div>
<div class="container">
<div class="angular-animation-container row">
<div ui-view class="shuffle-animation col-xs-12"></div>
</div>
</div>
</div>
</div>
</body>
拦截器注册:
var abpModule = angular.module('abp', []);
abpModule.config([
'$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push(['$q', function ($q) {
return {
'request': function (config) {
if (endsWith(config.url, '.cshtml')) {
config.url = abp.appPath + 'AbpAppView/Load?viewUrl=' + config.url + '&_t=' + abp.pageLoadTime.getTime();
}
return config;
},
'response': function (response) {
if (!response.config || !response.config.abp || !response.data) {
return response;
}
var defer = $q.defer();
abp.ng.http.handleResponse(response, defer);
return defer.promise;
},
'responseError': function (ngError) {
var error = {
message: ngError.data || abp.ng.http.defaultError.message,
details: ngError.statusText || abp.ng.http.defaultError.details,
responseError: true
}
abp.ng.http.showError(error);
abp.ng.http.logError(error);
return $q.reject(ngError);
}
};
}]);
}
]);
我从零开始安装,现在可以使用了。看起来我遗漏了一些小的配置错误。另外,显然ui网格不会干扰角度http拦截,所以结论是这是错误警报。我从头开始设置,现在可以工作了。看起来我遗漏了一些小的配置错误。另外,显然ui网格不会干扰角度http拦截,所以结论是这是错误警报。在我的模块初始化中,我有ui.grid而不是ui-grid。。。能帮忙吗?这里是打字错误,更新了Q。你怎么知道你的拦截器坏了?你试过添加断点和调试吗?我试过在某种程度上进行调试,但我在JS和angular方面不是很强,所以我不知道从哪里开始。我明白我应该从那些声明性指令被“解析”和执行的地方开始,但还没有深入挖掘。若你们能给我指出一些更具体的地方,那个就太好了。@Phil我在拦截器中有一个断点,当我删除ui网格时,它就会被击中。从应用程序的行为来看,拦截器中的逻辑并没有被执行。目前我毫不怀疑它不起作用。在我的模块初始化中,我有ui.grid而不是ui-grid。。。能帮忙吗?这里是打字错误,更新了Q。你怎么知道你的拦截器坏了?你试过添加断点和调试吗?我试过在某种程度上进行调试,但我在JS和angular方面不是很强,所以我不知道从哪里开始。我明白我应该从那些声明性指令被“解析”和执行的地方开始,但还没有深入挖掘。若你们能给我指出一些更具体的地方,那个就太好了。@Phil我在拦截器中有一个断点,当我删除ui网格时,它就会被击中。从应用程序的行为来看,拦截器中的逻辑并没有被执行。目前我毫不怀疑它不起作用。
var abpModule = angular.module('abp', []);
abpModule.config([
'$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push(['$q', function ($q) {
return {
'request': function (config) {
if (endsWith(config.url, '.cshtml')) {
config.url = abp.appPath + 'AbpAppView/Load?viewUrl=' + config.url + '&_t=' + abp.pageLoadTime.getTime();
}
return config;
},
'response': function (response) {
if (!response.config || !response.config.abp || !response.data) {
return response;
}
var defer = $q.defer();
abp.ng.http.handleResponse(response, defer);
return defer.promise;
},
'responseError': function (ngError) {
var error = {
message: ngError.data || abp.ng.http.defaultError.message,
details: ngError.statusText || abp.ng.http.defaultError.details,
responseError: true
}
abp.ng.http.showError(error);
abp.ng.http.logError(error);
return $q.reject(ngError);
}
};
}]);
}
]);