作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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}}
</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/
我是 Angular 新手。我正在将一些字段动态呈现到我的 react 形式中。当我使用 ng serve 时,一切都很好使用模拟请求(即渲染正确发生,console.log 中没有错误)。一旦我使用
我是一名优秀的程序员,十分优秀!