[英]Angularjs + strictdi error on http interceptor (typescript)
I'm writing a simple Angularjs test app using Typescript. 我正在使用Typescript编写一个简单的Angularjs测试应用程序。 I'm also enforcing ng-strict-di for minification purposes.
我也强制执行ng-strict-di用于缩小目的。
I created a simple app.ts file: 我创建了一个简单的app.ts文件:
declare var angular: ng.IAngularStatic;
module Application {
"use strict";
export var app: ng.IModule = angular.module("Private", ["ngRoute"]);
app.config(($httpProvider: ng.IHttpProvider) => {
$httpProvider.interceptors.push(Common.Services.HttpInterceptor.Factory);
});
app.config(["$routeProvider", ($routeProvider: ng.route.IRouteProvider) => {
$routeProvider.when("/home", { templateUrl: "home.html" });
$routeProvider.otherwise({ redirectTo: "/" });
}]);
}
As you can see, the HTTP Interceptor is pushing 如您所见,HTTP拦截器正在推动
Common.Services.HttpInterceptor.Factory
which is composed as is: 其组成如下:
module Common.Services {
export class HttpInterceptor {
public static Factory($http: ng.IHttpService) {
return new HttpInterceptor($http);
}
static $inject = ["$http"];
constructor($http: ng.IHttpService) {
}
public response = ((response) => { return response })
public responseError = ((rejection) => {
return rejection;
});
}
}
Simple as you see. 你看,简单。 But every time I hit the home i got this error:
但每次我到家时我都会遇到这个错误:
Error: [$injector:strictdi] function($http) is not using explicit annotation and cannot be invoked in strict mode http://errors.angularjs.org/1.4.9/ $injector/strictdi?p0=function(%24http)
错误:[$ injector:strictdi]函数($ http)未使用显式注释,无法在严格模式下调用http://errors.angularjs.org/1.4.9/ $ injector / strictdi?p0 = function(%24http )
But I inject the $http when 但我注入$ http时
static $inject = ["$http"];
I don't know how to fix this. 我不知道如何解决这个问题。
If this can be of any help, following the compiled js: 如果这有任何帮助,请遵循编译的js:
var Application;
(function (Application) {
"use strict";
Application.app = angular.module("Private", ["ngRoute"]);
Application.app.config(["$httpProvider", function ($httpProvider) {
$httpProvider.interceptors.push(Common.Services.HttpInterceptor.Factory);
}]);
Application.app.config(["$routeProvider", function ($routeProvider) {
$routeProvider.when("/home", { templateUrl: "home.html" });
$routeProvider.otherwise({ redirectTo: "/" });
}]);
})(Application || (Application = {}));
var Common;
(function (Common) {
var Services;
(function (Services) {
var HttpInterceptor = (function () {
function HttpInterceptor($http) {
this.response = (function (response) { return response; });
this.responseError = (function (rejection) {
return rejection;
});
}
HttpInterceptor.Factory = function ($http) {
return new HttpInterceptor($http);
};
HttpInterceptor.$inject = ["$http"];
return HttpInterceptor;
})();
Services.HttpInterceptor = HttpInterceptor;
})(Services = Common.Services || (Common.Services = {}));
})(Common || (Common = {}));
Thanks for any help! 谢谢你的帮助! V.
V.
下面的类HttpInterceptor
也注入工厂方法:
HttpInterceptor.Factory.$inject = ['$http'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.