Angular2 EXCEPTION: Attempt to detect changes on a dehydrated detector

前端 未结 2 1204
暖寄归人
暖寄归人 2021-01-25 09:15

I am having this error EXCEPTION: Attempt to detect changes on a dehydrated detector. and after reading a few online pages. I have not very clear how to fix it or b

2条回答
  •  伪装坚强ぢ
    2021-01-25 09:29

    After reading the commentary Eric Martinez. I solved in my case using OnDestroy and detach() in the tests I've done it seems to work well hope it helps others.

        import {Component, ChangeDetectorRef, OnDestroy} from "angular2/core";
        ..//
    
        export class Test implements OnDestroy{
        ..//
    
        constructor(http: Http, public ref: ChangeDetectorRef){
        ..//
    
                setInterval(() => {
                  this.ref.detectChanges();
                }, 5000);
    
        }
    
        ngOnDestroy(){
          this.ref.detach();
        }
    

    NOTE: I'm new to Angular2 and do not know if this really is the best solution

提交回复
热议问题