I am attempting to incorporate Angular NotifierService into my service class so that I can display error notifications in case of any exceptions from the service side.
I attempted to inject a bean of NotifierService in the constructor of my service class, but it is showing as undefined.
Could you please assist me in resolving this issue?
In app.service.ts
@Injectable({
providedIn: 'root'
})
export class AppService {
constructor(private http: HttpClient,private notifyService:NotifierService) {
}
.......
handleError(error) {
let errorMessage = '';
if (error.error instanceof ErrorEvent) {
// Get client-side error
errorMessage = error.error.message;
} else {
// Get server-side error
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
}
this.notifyService.notify('error', 'Internal Server error please contact Admin!!');//undefined
return throwError(errorMessage);
}
}
In app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
CommonModule,
AppRoutingModule,
HttpClientModule,
ReactiveFormsModule,
NotifierModule.withConfig(Constant.customNotifierOptions),
NgbModule
],
providers: [NotifierService],
bootstrap: [AppComponent]
})
export class ClaimDetailsModule { }
Error:
ERROR TypeError: Cannot read property 'notify' of undefined
at CatchSubscriber.handleError [as selector] (http://localhost:4200/main.js:2142:30)