Reputation: 5101
I am trying a simple APP_INITIALIZER
with my angular app, but getting error as
this.appInits[i] is not a function
- not able to figure out the issue.
here is my app module:
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
export function onAppInit1(){
return new Promise((resolve,reject) => {
return setTimeout(() => resolve(true), 5000);
})
}
@NgModule({
declarations: [
AppComponent,
SignInComponent
],
imports: [
],
providers: [
{
provide:APP_INITIALIZER,
useFactory:onAppInit1,//getting error
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: InsertAuthTokenInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule { }
Upvotes: 5
Views: 5542
Reputation: 6579
onAppInit1 should return a function that returns a promise
export function onAppInit1(){
return () => {
return new Promise((resolve,reject) => {
return setTimeout(() => resolve(true), 5000);
})
}
}
Upvotes: 19