如果您找到解决方案,我不知道我的Ngclass怎么工作
在我的HTML中:
<form [formGroup]="pageForm">
...
<input [(ngModel)]="namePage" type="text" class="form-control">
...
<div class="d-flex mt-4">
<i [ngClass]="{ 'is-valid': !f.name.errors }"></i>
</div>
</form>
在我的TS中:
pageForm: FormGroup;
namePage: string;
// the form
this.pageForm = new FormGroup({
name: new FormControl([this.namePage, Validators.required]),
});
get f() {
return this.pageForm.controls;
}
答案 0 :(得分:0)
尝试
isValid: boolean = false;
get f() {
this.isValid = this.pageForm.valid;
}
<form [formGroup]="pageForm" (ngSubmit)="f()">
...
<input [(ngModel)]="namePage" type="text" class="form-control">
...
<div class="d-flex mt-4">
<i [ngClass]="{ 'is-valid': isValid }"></i>
</div>
</form>