我正在使用Typescript使用Angular 1进行Web应用。我必须创建一个工厂,其中我有一些条件,我想要注入一些依赖。这是代码:
.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)
我该如何解决?