当我在angular中进行aot构建时,收到错误消息“ FormGroup”类型上不存在属性“第1节”。我已添加
<form [formGroup]="currentMonthForm" novalidate>
<table class="table spinwheel-table-blk">
<thead>
<tr COLSPAN=2 class="spinwheel-table-heading-block">
<th>Section ID</th>
<th><span>Points</span></th>
</tr>
</thead>
<tbody>
<tr COLSPAN=2>
<td>1</td>
<td>
<div class="input-group wingsclub-inputgroup">
<input type="text" class="form-control validation-field" placeholder="Points" aria-label="Recipient's username"
aria-describedby="basic-addon2" maxlength="3" formControlName="section1" [ngClass]="{ 'is-invalid': currentMonthForm.section1 }"
(input)="section1Change(1)">
<small class="text-danger" *ngIf="sectionFormErrors.section1">
<small class="text-danger" *ngIf="sectionFormErrors.section1">{{sectionFormErrors.section1}}</small>
</small>
</div>
</td>
</tr>
<table>
在组件中我有
currentMonthForm: FormGroup;
constructor(){
this.buildForm();
}
buildForm() {
this.currentMonthForm = this.fb.group({
section1: [null, Validators.compose([Validators.required, Validators.maxLength(3),
CustomValidators.number, this.validateNumber, CustomValidatorsInUse.isInteger, CustomValidatorsInUse.isPositiveInteger,])],})
但是我收到错误消息,'FormGroup'类型上不存在属性'section 1'。在aot构建中。但总的来说,它可以正常工作。
答案 0 :(得分:1)
似乎是罪魁祸首:
[ngClass]="{ 'is-invalid': currentMonthForm.section1 }"
JIT编译器不会检查对象上是否确实存在该属性,但是AOT构建会检查该属性,并且它抱怨currentMonthForm
FormGroup没有该属性。
您应该修复is-invalid
类的条件,因为它目前很奇怪。我期望像这样:
[ngClass]="{ 'is-invalid': currentMonthForm.get('section1').errors !== null }"