1

I have something like this:

@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
    }
}

and from my main.ts I have:

export function main(screenUrl) {
    platformBrowserDynamic().bootstrapModule(AppModule, {providers: [ { provide :  BootstrapParams, useFactory: () => new BootstrapParams("/bla/bla") }]});
}

But this is throwing

"Can't resolve all parameters for AppModule: (?).(…)"

and I do not understand what I am doing wrong, I have read all the documentation, but there are not many example of passing data to the root module.

lqbweb
  • 1,684
  • 3
  • 19
  • 33

1 Answers1

0

Ok, I answer myself, the problem seems to be on declaring BootstrapParams in the same file as the AppModule. It can be in the same file, but it has to be declared before. Like:

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  ) {
    }
}
lqbweb
  • 1,684
  • 3
  • 19
  • 33
  • 1
    What you have before, `BootstrapParams` have after `AppModule`? The problem seems to be similar like [this question](http://stackoverflow.com/q/34838804/2435473) – Pankaj Parkar Sep 06 '16 at 13:47
  • yes exactly, it is the same problem. thanks for your help! – lqbweb Sep 06 '16 at 14:30