@Inject('ServiceName') is not working in strictdi mode
erdysson opened this issue · comments
Erdi Taner Gokalp commented
I am not able to run my app with angular's strictdi mode since @Inject() does not call $injector I guess. This is the constructor part of my service :
@Injectable()
export class UserService {
private user: Resource;
...
constructor(
@Inject('ResourceService') ResourceService: ResourceService,
@Inject('ConfigService') ConfigService: ConfigService,
@Inject('PubSubService') private PubSubService: PubSubService,
@Inject('LogService') private LogService: LogService
) { ... }
}
And error log on console :
Uncaught Error: [$injector:strictdi] UserService is not using explicit annotation and cannot be invoked in strict mode
http://errors.angularjs.org/1.6.3/$injector/strictdi?p0=UserService
at 403b0a6.classic.dependencies.js:30263
at Function.annotate [as $$annotate] (403b0a6.classic.dependencies.js:34406)
at injectionArgs (403b0a6.classic.dependencies.js:35157)
at Object.instantiate (403b0a6.classic.dependencies.js:35212)
at Object.<anonymous> (403b0a6.classic.dependencies.js:35049)
at Object.invoke (403b0a6.classic.dependencies.js:35200)
at Object.enforcedReturnValue [as $get] (403b0a6.classic.dependencies.js:35033)
at Object.invoke (403b0a6.classic.dependencies.js:35200)
at 403b0a6.classic.dependencies.js:34992
at getService (403b0a6.classic.dependencies.js:35141)
Is there anyway that I can force @Inject() to call $injector or solve this problem ?
Anthony Ciccarello commented
@erdysson How are you initializing your UserService
? If you are using @NgModule
or provide()
it should set up the dependency injection. I've requested a helper for $inject
when not using these methods but you should in most cases be providing your service to angular via ng-metadata.
Anthony Ciccarello commented
Closing as not reproducible