2
我正在使用Typescript来处理Angular 1的Web应用程序。我必须创建一个工厂,在这个工厂中我有一些我想要注入一些依赖性的条件。这是代码:注入不能在Typescript中工作
.factory('myFactory', function ($q: angular.IQService, $location: ng.ILocationService, $localStorage: any, Ob: any, $injector: ng.auto.IInjectorService) {
return {
f: function (config: any) {
config.headers = config.headers || {};
if (Ob.auth) {
let $state = $injector.get("$state");
$state.go("app.auth");
}
return config;
},
.... other methods....
};
})
我编译时有此错误控制台:
ts\inj.ts(110,14): error TS2339: Property 'go' does not exist on type '{}'.
ts\inj.ts(126,13): error TS2339: Property 'go' does not exist on type '{}'.
[10:46:55] TypeScript: 2 semantic errors
[10:46:55] TypeScript: emit succeeded (with errors)
我该如何解决呢?
我想将用户重定向到该状态,并且'get'它给了我同样的错误 – panagulis72
即使用'get'替换它们,完全相同的错误也完全一样吗?即使你的代码中没有'go'? – Aron