gpt4 book ai didi

javascript - 类型错误 : Cannot read property '_rawValidators' of null after Ng build

转载 作者:行者123 更新时间:2023-12-05 00:26:02 25 4
gpt4 key购买 nike

我是 Angular 新手。我正在将一些字段动态呈现到我的 react 形式中。当我使用 ng serve 时,一切都很好使用模拟请求(即渲染正确发生,console.log 中没有错误)。一旦我使用 ng build 构建项目并使用适当的后端,我得到我动态渲染的每个字段的错误:

main.js:1 ERROR TypeError: Cannot read property '_rawValidators' of null 
我找不到有关此错误的任何背景。我很想听听你的想法。
更多背景
// these fields change with selection
this.datafields = [{
dfId: 48,
dfName: "Phone",
dfType: "text",
dfOptions: null,
dfValue: ""
},
{
dfId: 49,
dfName: "Eval",
dfType: "select",
dfOptions: ["","Remote","Live"],
df_value: "",
}]
ngOnInit 中的 typescript 渲染(试过 ngAfterViewInit 没有改善)
dfGroup = new FormGroup({})
...
...

this.eyeForm = this.formBuilder.group({
focus: ['', Validators.required],
datafields: this.formBuilder.array([])
})

...
...

if (this.datafields != null || this.datafields != undefined) {
this.datafields.forEach((x:any) => {
this.dfGroup.setControl(x.dfName, new FormControl(x.dfValue));
});
this.getDataFields.push(this.dfGroup);
}
HTML 如下所示:
 <div [formGroup]="dfGroup">
<div class="row pt-2" *ngFor="let field of datafields; let i=index">
<div class="col-4 d-flex align-items-center 13required">
{{field.dfName}}&nbsp;
</div>
<div class="col-6">
<mat-form-field *ngIf="field.dfType == 'text'" appearance="outline">
<input
matInput
[type]="field.dfType"
[formControlName]="field.dfName"
required
/>
</mat-form-field>
<mat-form-field
*ngIf="field.dfType == 'select'"
appearance="outline"
>
<mat-select [formControlName]="field.dfName" placeholder="">
<mat-option
[value]="option"
*ngFor="let option of field.dfOptions"
>
{{ option }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
</div>

最佳答案

当我模拟我的模板并拼写我的 formControlName 属性时,我遇到了这种情况。

<mycomponent formControlName="bogusfieldSpelledWrong" ...>
为什么 Angular 显示它,因为这个错误可能与组件如何初始化/更改表单有关。

关于javascript - 类型错误 : Cannot read property '_rawValidators' of null after Ng build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69028717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com