无法读取未定义的属性“已启用”

在代码中。我必须以反应形式设置控件的值。


ngDoCheck() {

   setControlValues();

}


ngChanges(changes: SimpleChanges): void {

   setControlValues();

}


private setControlValues() {

   try {

   theForm.Controls['class'].setValue(myValue); //error happens here

   // ...many controls

   }

   catch(e) {

      console.log(e);

   }

}

但是我得到了例外。


无法在 eval (forms.js:4852) at(forms.js:4873) at eval(forms.js.4793) at Array.forEach() at FormGroup._forEachChild 处读取未定义的属性“已启用”..... .at FormControl.AbstractControl.updateValueAndValidity (forms.js: 3393)


表格定义为


theForm: FormGroup;

constructor(private fb: FormBuilder) {

    this.useForm = this.fb.group({

    class: [null]

 });

}

我的 html 是:


<texearea kendoYextArea

     formControlName="class" required></textarea>

更新:


我发现库中的 forms.js 代码如下。


 AbstractControl.prototype.updateValueAndValidty =

 function(opts) {

    if(opts == void 0) { opts = {}; }

    this._setInitialStatus();

    if(this.enabled ) {

        this._cancelExistingSubscription();


白衣非少年
浏览 165回答 1
1回答

12345678_0001

还是没有头绪。但如果我使用&nbsp;theForm.Controls['class'].patchValue(myValue)然后错误消失了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript