Javascript 注射不';我不能用打字机打字
我正在用Typescript做一个带有Angular 1的web应用程序。我必须创建一个工厂,在其中我有一些条件,我想在其中注入一些依赖项。代码如下:Javascript 注射不';我不能用打字机打字,javascript,angularjs,typescript,Javascript,Angularjs,Typescript,我正在用Typescript做一个带有Angular 1的web应用程序。我必须创建一个工厂,在其中我有一些条件,我想在其中注入一些依赖项。代码如下: .factory('myFactory', function ($q: angular.IQService, $location: ng.ILocationService, $localStorage: any, Ob: any, $injector: ng.auto.IInjectorService) { return {
.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)
如何解决它?查看它时,$state对象似乎没有
go()
方法,这就是TypeScript抛出错误的原因。你是不是想用$state.get()
来代替?我想将用户重定向到该状态,使用“get”会在完全相同的行上产生相同的错误,即使你用get
替换它们,也会产生相同的错误?即使代码中不再有go
?