I have a save button outside form. on save button click i want to display mat error
. But it does not get displayed. I Tried using this.form.markAsDirty()
& this.form.markASTouched()
but nothing works.
<form [formGroup]="form">
<div formArrayName="products" *ngFor="let product of form.get('products').controls; let i = index;">
<div [formGroupName]="i">
<mat-form-field>
<input type="text" formControlName="productCode">
<mat-error>
Blank Error
</mat-error>
</mat-form-field>
<mat-form-field>
<input type="text" formControlName="productName">
<mat-error>
Blank Error
</mat-error>
</mat-form-field>
</div>
</div>
<form>
<div>
<button type="button" (click)="SaveProducts()">Save</button>
</div>
angular code:
addProduct() {
this.form.get('products').push(this.getProductGroup())
}
SaveProducts() {
this.form.markAsDirty();
this.form.markAsTouched();
if(this.form.valid) {
//save products
}
}