I'm doing a web app with Angular 1 using Typescript. I have to create a Factory in which I have some conditions in which I want to inject some dependences. This is the code:
.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....
};
})
When I compile I have this error in console:
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)
How can I solve it?
Looking at this page it doesn't look like the $state object has a go()
method, which is why TypeScript is throwing an error. Did you mean to use $state.get()
instead?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.