ng2-toastr在Angular 4.3.6中调用时未应用正确的css服务
我试图在我的应用程序中实现ng2-toastr。我在"@angular/compilercli": "^4.3.6",
。我有以下拦截器来拦截Http的错误。ng2-toastr在Angular 4.3.6中调用时未应用正确的css服务
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);
});
}
}
而在我的部分,我在我的@NgModule
声明imporinting ToastModule.forRoot()
后设置我的RootViewContainerRef。
constructor(public toastr: ToastsManager, vRef: ViewContainerRef) {
this.toastr.setRootViewContainerRef(vRef);
}
出于某种原因,它编译罚款,我也看到console.log('---> status:', evt.status);
线在控制台中的服务的日志,但没有看到任何toastr显示。但是,当我在浏览器中检查组件时,我可以看到吐司容器。我不知道我在这里错过了什么。任何指导将不胜感激。我的实施有什么问题?
嗨你InterceptorService本身添加此onedeclaration,无需添加组件
constructor(public toastr: ToastsManager, vRef: ViewContainerRef) {
this.toastr.setRootViewContainerRef(vRef);
}
不要忘记在我@NgModule做一个ToastModule.forRoot()必须工作
但是,当我在浏览器中检查组件时,我可以看到吐司容器。
那个烤面包机的容器是否有style =“display:none;” ?因为从4.3.5到4.3.6,动画改变了某些东西,我还面临动画的一些问题,组件被渲染并且应该淡入,但它被设置为显示:无。
如果你会看到显示:没有,这意味着一些错误的动画。
不是。我看到没有任何风格的委员会适用于它。 –
角被更新为4.1.1,似乎一些问题与动画是固定的。让我们尝试更新到4.1.1,看看你是否还有问题。
我在角4.2
尝试同样的问题补充以下。它应该工作..
@import” ../node_modules/ng2-toastr/ng2-toastr.css'; to ./src/app/theme/theme.cscc
您无法将“ViewContainerRef”添加到服务中,因为服务在自然中是单身人士.https://stackoverflow.com/questions/40636840/how-can-i-inject -viewcontainerref-into-a-service –