Injection issue with InjectionToken
See original GitHub issueI’m submitting a…
[ x] Bug report
Current behavior
When I run this example, I get an exception in the console
TypeError: Cannot read property 'ngInjectableDef' of undefined
at resolveNgModuleDep (vendor.js:39470)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (vendor.js:40174)
at inject (vendor.js:32520)
at injectArgs (vendor.js:32551)
at vendor.js:32608
at _callFactory (vendor.js:39548)
at _createProviderInstance (vendor.js:39506)
at resolveNgModuleDep (vendor.js:39481)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (vendor.js:40174)
at resolveDep (vendor.js:40539)
Expected behavior
No exception should occur and injection should be made
Minimal reproduction of the problem with instructions
@Injectable({
providedIn: 'root'
})
export class AppService {
constructor(@Inject(APP_CONFIG) private config:Config) {
}
}
export const APP_CONFIG = new InjectionToken<Config>
('app.config', {
providedIn: 'root',
factory: () => AppConfig
});
export interface Config {
apiUrl: string;
}
export const AppConfig: Config = {
apiUrl: 'http://localhost:8080/api/'
};
Environment
Angular version: 6.1.8
Browser:
- [x ] Chrome (desktop) version 69.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:16 (2 by maintainers)
Top Results From Across the Web
InjectionToken - Angular
Use an InjectionToken whenever the type you are injecting is not reified (does not have a runtime representation) such as when injecting an...
Read more >Angular Injection Token use cases - Country Code - Ghost
An Angular Injection Token is no different. You create an Injection Token by calling new InjectionToken('some description string'), this returns ...
Read more >Configure your Angular apps with an injection token - Medium
Players of dependency injection in Angular: provider, injector and requesting component. Today we are going to have a look at a practical use...
Read more >Injection Token in Angular - TekTutorialsHub
The Injection Token allows creating token that allows the injection of values that don't have a runtime representation. It is very similar to ......
Read more >Inject() for InjectionToken declared in module fails in angular2
Recently I've run into problem with InjectionToken, that is declared in module import {InjectionToken, NgModule} from '@angular/core'; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Verified this issue on Angular 7.2.4. I still got an error but the error message is different:
Not reproduced any more with Angular9-rc.9