阅读所有类似的主题后,任何解决方案都无法帮助我解决此问题:
在html中:
<form [formGroup]="project-name-form" (ngSubmit)="onImportClick()">
<div class="form-group">
<input type="text" formControlName="projectName" class="form-control" [ngClass]="{ 'is-invalid': submitted && form.projectName.errors }" />
<div *ngIf="submitted && form.projectName.errors" class="invalid-feedback">
<div *ngIf="form.projectName.errors.required">Project name is required</div>
</div>
</div>
</form>
在ts中:
constructor(
public dialogRef: MatDialogRef<ImportProjectDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private formBuilder: FormBuilder){
this.projectNameForm = this.formBuilder.group({
projectName: new FormControl(null, [Validators.required, Validators.minLength(1)])
});
}
应用模块中的导入设置正确。有人可以帮忙吗?
答案 0 :(得分:1)
不能命名变量
project-name-form
组件的属性实际上称为
projectNameForm
您需要将其传递给[formGroup]
[formGroup]="projectNameForm"