有时候,直到我重新加载页面,角度烘烤器才起作用,直到重新加载html元素toast-container才出现在html中:
导入:
import { ToastsManager } from 'ng2-toastr';
....
constructor(public toastr: ToastsManager){}
...
if (bDm === false) {
this.toastr.warning('xxxx', 'yyyy');
return false;
}
在app.modules中
import { ToastModule, ToastOptions } from 'ng2-toastr/ng2-toastr';
....
imports: [
ToastModule.forRoot()
]
在package.json中,我得到了:
"ng2-toastr": "^4.1.2",
通过我使用的导航器是google chrome,在控制台中不会出现错误。
最诚挚的问候!
答案 0 :(得分:0)
我认为我找到了解决方案,或者至少对我有用:我有多模块应用程序,因此在有此问题的模块中我添加了:
在xxxx.components.ts中:
constructor(public vcr: ViewContainerRef,
public toastr: ToastsManager) {
this.toastr.setRootViewContainerRef(vcr);
}