Angular2例外:尝试检测脱水探测器上的变化 [英] Angular2 EXCEPTION: Attempt to detect changes on a dehydrated detector

查看:245
本文介绍了Angular2例外:尝试检测脱水探测器上的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误异常:尝试检测脱水探测器上的变化和阅读几页网上后。我不是很清楚如何解决它,或因为它是。

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 because it is.

<一个href=\"https://github.com/angular/angular/blob/e7ad03cba6696fac4eed282ecccd5eb85a36ddb6/modules/angular2/src/core/change_detection/exceptions.ts#L87\" rel=\"nofollow\">https://github.com/angular/angular/blob/e7ad03cba6696fac4eed282ecccd5eb85a36ddb6/modules/angular2/src/core/change_detection/exceptions.ts#L87

错误在我的情况下,开始时我把一些零部件,而使用 @RouteConfig RouterLink

The error begins in my case when I put some components while using @RouteConfig RouterLink

和我的部件之一使用此构造

and one of my components use this constructor

constructor(http: Http, private ref: ChangeDetectorRef) {
            ..//
            setInterval(() => {
              this.ref.detectChanges();
            }, 5000);

如果我评论并改变构造是这样的错误会消失。

if I comment and change the constructor something like this error disappears

constructor(http: Http) {
                ..//
                /*
                   setInterval(() => {
                     this.ref.detectChanges();
                   }, 5000);
                */

有人是这样的,或任何其他使用来解决它 ChangeDetectorRef

推荐答案

阅读评论埃里克·马丁内斯后。我解决了我的情况下,使用的OnDestroy 分离()在我所做的测试中,它似乎运作良好希望它可以帮助别人。

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();
    }

请注意:我是新来Angular2,不知道如果这真的是最好的解决方案。

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

这篇关于Angular2例外:尝试检测脱水探测器上的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆