5

I'm using ng2-toastr and getting the below error

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

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

I have this in a button click event.

sudhir
  • 1,387
  • 3
  • 25
  • 43
  • Are you doing some actions in an `ngOnDestroy()`? – Günter Zöchbauer Feb 21 '17 at 13:35
  • No , nothing.I didnot have any ngOnDestroy method – sudhir Feb 22 '17 at 02:10
  • I am having the exact same error, also on a click event. My problem was that I display a material design snackbar, and when the button is clicked in rapid succession, the error is thrown. This is supposedly fixed in a newer version of material: https://github.com/angular/material2/pull/2392. This is quite specific though, and you are probably having a different problem. I'd try to strip away some actions in your click event function and narrow it down to what specifically causes the error to occur.. – Jort Feb 24 '17 at 07:42
  • have a look at this http://stackoverflow.com/questions/36042125/use-toastr-with-angular2/42239840#42239840 – Aravind Feb 26 '17 at 13:35
  • You can find answer here: http://stackoverflow.com/questions/42386249/angular-2-loading-nested-component-is-destroying-the-existing-scope-of-ng2-toa – sudhir Feb 26 '17 at 17:09

1 Answers1

-3

add this:

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

and change in node_modules/ng2-toastr/bundle/toast-manager.js:

ToastsManager.prototype.dispose = function () {
    var _this = this;
    if (_this.container) {
        _this.container.destroy();
        _this.container = null;
    }
};
currarpickt
  • 2,290
  • 4
  • 24
  • 39