什么是脱水器和如何我使用一个在这里? [英] What is a dehydrated detector and how am I using one here?

查看:228
本文介绍了什么是脱水器和如何我使用一个在这里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个简单的指令集中文本输入时使用的元素 * ngIf 激活。这是一个包含 * ngFor 循环中。

I'm using a simple directive to focus a text input when the element is active using *ngIf. This is contained within a *ngFor loop.

在第一个 * ngIf 被激活,输入侧重预期。当另一个输入激活我的错误:

When the first *ngIf is activated, the input focuses as expected. When another input is activated I get the error:

异常:尝试使用脱水器

我不明白这是什么意思,我怎么能prevent错误。该功能仍然即使有错误的原理。

I don't understand what this means and how I can prevent the error. The functionality still works even with the error.

@Directive({
    selector: '[myAutoFocus]'
})
export class AutoFocusDirective {
    constructor(private elem: ElementRef) {
        window.setTimeout(function() {
            elem.nativeElement.querySelector('input').focus();
        });
    }
}

```

推荐答案

脱水器是已经从变化检测系统中删除的组件,通常是因为它已通过<$已卸载从DOM C $ C> * ngIf 或其他方式:
<一href=\"https://github.com/angular/angular/blob/master/modules/angular2/src/core/change_detection/abstract_change_detector.ts#L167\">https://github.com/angular/angular/blob/master/modules/angular2/src/core/change_detection/abstract_change_detector.ts#L167
如果有在达到这个已经卸载检测应用程序中的异步操作,则会引发错误:
<一href=\"https://github.com/angular/angular/blob/master/modules/angular2/test/core/change_detection/change_detector_spec.ts#L1180\">https://github.com/angular/angular/blob/master/modules/angular2/test/core/change_detection/change_detector_spec.ts#L1180
解决方案是使用 [隐藏] 而不是 * ngIf 受影响的组件,或者推迟违规行动,下一个剔使用的setTimeout(()=&GT; this.offendingAction(),0)

Dehydrated detector is a component that has been removed from the change detection system, usually because it has been unmounted from DOM by *ngIf or other means: https://github.com/angular/angular/blob/master/modules/angular2/src/core/change_detection/abstract_change_detector.ts#L167 If there's an asynchronous action in the application that hits this already unmounted detector, error is thrown: https://github.com/angular/angular/blob/master/modules/angular2/test/core/change_detection/change_detector_spec.ts#L1180 solution is to use [hidden] instead of *ngIf on the affected component, or defer the offending action to next tick using setTimeout( () => this.offendingAction(), 0)

这篇关于什么是脱水器和如何我使用一个在这里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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