I am trying to implement ng2-toastr in my application. I am on "@angular/compilercli": "^4.3.6",
. I have the following Interceptor to intercept errors form the Http.
export class InterceptorService implements HttpInterceptor {
constructor(public toastr:ToastsManager) {
}
intercept(req:HttpRequest<any>,
next:HttpHandler):Observable<HttpEvent<any>> {
//Inspection removed for this file for rxjs.
//noinspection TypeScriptValidateTypes
return next.handle(req).do(evt => {
if (evt instanceof HttpResponse) {
this.toastr.success('You are awesome!', 'Success!');
console.log('---> status:', evt.status);
// console.log('---> filter:', req.params.get('filter'));
}
}, err => {
if (err instanceof HttpErrorResponse) {
this.toastr.error('This is not good!', 'Oops!');
//toastr here
}
console.log(err);
});
}
}
And in my component I am setting my RootViewContainerRef after imporinting ToastModule.forRoot()
in my @NgModule
declaration.
constructor( public toastr: ToastsManager, vRef: ViewContainerRef) {
this.toastr.setRootViewContainerRef(vRef);
}
For some reason it compiles fine and I also see the log from console.log('---> status:', evt.status);
line of the services in console but don't see any toastr displayed. I however can see the toast container when I inspect the component in browser. I don't know what I am missing here. Any guide will be appreciated. What is wrong with my implementation?