Reputation: 1040
I want to load api data before app onInit(). I am not able to inject the service dependency.
How I can inject that?
import { GetComissionService } from '../app/services/get-comission.service';
function initializeApp(comissionService: GetCommissionService): Promise<void> {
return new Promise((resolve, reject) => {
GetComissionService.getCommission('item').subscribe(data => {
console.log(data);
resolve();
})
});
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule
],
providers: [{
provide: APP_INITIALIZER,
deps: [GetComissionService],
useFactory: () => initializeApp,
multi: true
}],
bootstrap: [AppComponent]
})
EDIT 1: adding error message images
Getting these errors while injecting service
Upvotes: 0
Views: 3165
Reputation: 4597
You also need to have a parameter on the initializeApp
function for the service. Try this:
export function initializeApp(comissionService: GetComissionService): Promise<any> {
return new Promise((resolve, reject) => {
comissionService.getCommission('item').subscribe(data => {
console.log(data);
resolve();
})
});
}
Upvotes: 1