Angular 2 错误 : Attempt to use a destroyed view: detectChanges Error: Attempt to use a destroyed view: detectChanges at ViewDestroyedError

标签 angular

我正在使用 ng2-toastr 并收到以下错误

https://www.npmjs.com/package/ng2-toastr

Attempt to use a destroyed view: detectChanges Error: Attempt to use a destroyed view: detectChanges at ViewDestroyedError

我在按钮点击事件中有这个。

最佳答案

添加这个:

ngOnDestroy() {
    this.helper.toastr.dispose();}

并更改 node_modules/ng2-toastr/bundle/toast-manager.js:

ToastsManager.prototype.dispose = function () {
    var _this = this;
    if (_this.container) {
        _this.container.destroy();
        _this.container = null;
    }
};

关于 Angular 2 错误 : Attempt to use a destroyed view: detectChanges Error: Attempt to use a destroyed view: detectChanges at ViewDestroyedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42367498/

相关文章:

Angular 输入必填字段不起作用

angular - 是否可以在 Angular 2+ 中进行条件内容投影(包含)

angular - 我可以在 Angular 7 中向 'window' 对象添加属性吗?

javascript - 如何在 Angular2 中包含 Youtube Iframe API?

node.js - 在 Node 与 nginx 中服务 Angular

javascript - 带高度的 Angular Material 垫抽屉问题

javascript - Angular2 - 从子组件访问父组件的变量

html - 如何制作 Angular Material 卡以占用可用的垂直空间并使其内容可滚动

从 http.get() 加载的 JSON 数据在我的 Angular 2 模板中未定义

angular - 将 'hidden' 类应用于组件而不是使用 *ngIf 隐藏它们是否是一种不好的做法? - Angular