找不到带有名称注释的控件。为什么无法识别控件名称?
如您在模板上看到的,我有控件名称注释。
#Code
initFormGroups(): void {
const sectionGroups = {};
this._sections.forEach((section: TemplateSection, sectionIndex: number) => {
const sectionGroup = {};
section.questions.forEach(({ rephrase, question, notes }: Question, questionIndex) => {
sectionGroup[questionIndex] = [rephrase || question];
});
sectionGroups[sectionIndex] = this.formBuilder.group(sectionGroup);
return null;
});
this.form = this.formBuilder.group(sectionGroups );
}
#my模板
<form [formGroup]="form" name="form" *ngIf="form">
<ng-container *ngFor="let section of _sections; let sectionIndex = index">
<mat-card class="question" *ngFor="let question of section.questions; let questionIndex = index">
<ng-container *ngIf="question.notes">
<mat-form-field appearance="outline"
class="pr-4 clickable-mat-form-field"
(click)="editNote(sectionIndex, questionIndex, question)"
>
<mat-label>Note</mat-label>
<input class="hidden" matInput>
<editor class="mat-input-element"
[disabled]="true"
matInput formControlName ="notes"
[init]="tinyMCEConfig">
</editor>
</mat-form-field>
答案 0 :(得分:0)
您拥有*ngIf="form"
,因此整个模板在您设置this.form
之前不存在