Reputation: 390
I don't know how my Ngclass not working, if you found the solution thank you soo much
In my 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>
In my TS:
pageForm: FormGroup;
namePage: string;
// the form
this.pageForm = new FormGroup({
name: new FormControl([this.namePage, Validators.required]),
});
get f() {
return this.pageForm.controls;
}
Upvotes: 1
Views: 7607
Reputation: 443
Try
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>
Upvotes: 1