Я пытаюсь глобально внедрить значение в контейнер DI моего приложения в Angular 2 в соответствии с официальная документация.
Однако я получаю сообщение об ошибке:
compiler.es5.js:1540 Uncaught Error: Can't resolve all parameters for AppComponent: (?).
at syntaxError (http://localhost:4200/vendor.bundle.js:30216:34)
at CompileMetadataResolver._getDependenciesMetadata (http://localhost:4200/vendor.bundle.js:43553:35)
at CompileMetadataResolver._getTypeMetadata (http://localhost:4200/vendor.bundle.js:43421:26)
at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:4200/vendor.bundle.js:43030:24)
at CompileMetadataResolver._getEntryComponentMetadata (http://localhost:4200/vendor.bundle.js:43674:45)
at http://localhost:4200/vendor.bundle.js:43257:110
at Array.map (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:43257:73)
at JitCompiler._loadModules (http://localhost:4200/vendor.bundle.js:54306:66)
at JitCompiler._compileModuleAndComponents (http://localhost:4200/vendor.bundle.js:54265:52)
Вот мои классы:
app.module.ts
import {BrowserModule} from '@angular/platform-browser';
import {InjectionToken, NgModule} from '@angular/core';
import {AppComponent} from './app.component';
export interface AppConfig {
apiEndpoint: string;
title: string;
}
export const HERO_DI_CONFIG: AppConfig = {
apiEndpoint: 'api.heroes.com',
title: 'Dependency Injection'
};
export let APP_CONFIG = new InjectionToken<AppConfig>('app.config');
@NgModule({
imports: [
BrowserModule
],
declarations: [
AppComponent
],
providers: [
{ provide: APP_CONFIG, useValue: HERO_DI_CONFIG }
],
bootstrap: [AppComponent]
})
export class AppModule {
}
app.component.ts
import {Component as NgComponent, Inject} from '@angular/core';
import {APP_CONFIG, AppConfig} from './app.module';
@NgComponent({
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent {
constructor (@Inject(APP_CONFIG) config: AppConfig) {
console.log(config.apiEndpoint, config.title);
}
}
В чем может быть проблема и какую стратегию отладки следует использовать? Ошибка и трассировка стека мне здесь не очень помогают.
app.module.ts
в других файлах. 18.05.2017