我有这样的事情:
@NgModule({
imports: [ BrowserModule ],
declarations: [ LoaderComponent ],
bootstrap: [ LoaderComponent ],
})
export class AppModule {
constructor( private params : BootstrapParams ) {
}
}
export class BootstrapParams {
public urlParam : String;
constructor(screenUrl : String) {
this.urlParam = screenUrl
}
}
从我的主要文件中我有:
export function main(screenUrl) {
platformBrowserDynamic().bootstrapModule(AppModule, {providers: [ { provide : BootstrapParams, useFactory: () => new BootstrapParams("/bla/bla") }]});
}
但是这就是投掷
"Can't resolve all parameters for AppModule: (?).(…)"
我不明白我做错了什么,我已经阅读了所有文档,但没有很多将数据传递给根模块的例子。
答案 0 :(得分:0)
好的,我回答自己,问题似乎是在与AppModule相同的文件中声明BootstrapParams。它可以在同一个文件中,但必须在之前声明。像:
export class BootstrapParams {
public urlParam : String;
constructor(screenUrl : String) {
this.urlParam = screenUrl
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ LoaderComponent ],
bootstrap: [ LoaderComponent ],
providers: [ { provide : BootstrapParams, useFactory: () => new BootstrapParams("/bla/bla") }]
})
export class AppModule {
constructor( private params : BootstrapParams ) {
}
}