Свойство 'section 1' не существует для типа 'FormGroup'.не строй - PullRequest
0 голосов
/ 09 ноября 2018

Когда я делаю сборку в angular, я получаю сообщение об ошибке. Свойство 'section 1' не существует для типа 'FormGroup'. Я добавил

<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,])],})

Но я получаю сообщение об ошибке. Свойство 'section 1' не существует для типа 'FormGroup'. в отличном состоянии. Но в целом собери свою корректную работу.

1 Ответ

0 голосов
/ 09 ноября 2018

Похоже, виновник таков:

[ngClass]="{ 'is-invalid': currentMonthForm.section1 }"

JIT-компилятор не проверяет, действительно ли свойство существует на объекте, но сборка AOT делает это, и жалуется, что currentMonthForm FormGroup не имеет этого свойства. Вы должны исправить условие для класса is-invalid, поскольку это очень странно в настоящее время. Я бы ожидал что-то вроде:

[ngClass]="{ 'is-invalid': currentMonthForm.get('section1').errors !== null }"
...