Angular2(素β3)QUOT;它检查&QUOT后的前pression发生变化的;在更新表单值 [英] Angular2 (beta3) "expression has changed after it was checked" in updating form values

查看:278
本文介绍了Angular2(素β3)QUOT;它检查&QUOT后的前pression发生变化的;在更新表单值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Angular2(试用版3 TS)(一种我的previous一篇关于嵌套形式的延续<一个href=\"http://stackoverflow.com/questions/35208504/angular2-beta-nesting-form-based-parent-child-components-and-validating-from-pa\">Angular2测试:嵌套基于表单的父/子组件和从父验证),但我发布一个新的问题,因为它涉及到不同类型的问题

This is a sort of continuation of my previous post about nested forms in Angular2 (beta 3 with TS) (Angular2 beta: nesting form-based parent/child components and validating from parent), but I'm posting a new question as it refers to a different type of issue.

您可以在这里找到 HTTP这里描述的问题在摄制:// plnkr。 CO /编辑/ iCmmy9at2wF5qY0P6VmV 。总之,在这个假的情况我有一个分量重$ P $从一个虚构的字典psenting一个字,并用于重新present各意义这个词的另一个子组件;因此,有父组件及其子之间的1对多的关系。两者都基于表单的模板,与表单生成器生成。子模板是 NgFor ,在这里我感觉每个从父绑定(=字)模型内部。这样,每个字的意义上所有的属性都自动绑定到这个词的典范。

You can find the repro of the issue described here at http://plnkr.co/edit/iCmmy9at2wF5qY0P6VmV. In short, in this fake scenario I have a component representing a single word from an imaginary dictionary, and another child component used to represent each sense for that word; thus, there is a 1-to-many relation between the parent component and its children. Both have a form-based template, built with a form builder. The child template is inside a NgFor, where I bind each sense from the parent (=word) model. This way, all the properties of each word's sense are automatically bound to the word's model.

这些属性的一些附加若干验证程序(无论是自定义或标准)。我的问题是,当我编程设置为从父组件字模型(这也意味着设置窗体的控件的值),这似乎触发在验证过程中的一些竞争条件,这引起了类型的几个例外的异常:防爆pression'!definitionCtl.valid有人检查后发生了变化。 previous值:真。当前值:'假',它阻止进一步的code执行

Some of these properties have several validators attached (either custom or standard). My issue is that when I programmatically set the word model from the parent component (which also implies setting the value of the form's controls), this seems to trigger some race condition in the validation process, which raises several exceptions of type EXCEPTION: Expression '!definitionCtl.valid' has changed after it was checked. Previous value: 'true'. Current value: 'false', which block further code execution.

据我所知,这似乎与这个问题有关的唯一信息是在这里:

AFAIK, the only information which seems related to this issue is here:

  • https://github.com/angular/angular/issues/5992,
  • Angular2: Nested *ngFor resulting in 'Expression has changed after it was checked'

然而,对于我的问题的解决方案似乎并不处于手从这些讨论中,除非(如果我没有理解好),我选择手动管理我所有的绑定,我想避免,如在真实世界应用程序会有很多人。谁能帮助?

Yet a solution for my issue does not seem to be at hand from those discussions, unless (if I understand well) I opt for manually managing all my bindings, which I'd like to avoid, as in the real-world application there will be lots of them. Could anyone help?

推荐答案

您可以尝试禁用Angular2开发模式:

You could try to disable the Angular2 dev mode:

import {bootstrap} from 'angular2/platform/browser';
import {App} from './app';
import {enableProdMode} from 'angular2/core';

enableProdMode();

bootstrap(App, [])
  .catch(err => console.error(err));

查看君特的回答更多细节:

See the Günter's answer for more details:

  • In Angular2, why are there 2 times check for content and view after setTimeout?

这篇关于Angular2(素β3)QUOT;它检查&QUOT后的前pression发生变化的;在更新表单值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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