Creating dynamic textboxes with *ngFor in Angular
<tr *ngFor="let computer in _Computers; let i = index;">
<td>{{computer.Name}}</td><td>{{computer.Optional}}</td>
<td> <input matInput [formControl] = "frmCtrl" name="UnitofPrice" [(ngModel)]="computer[i]">
</td>
<td>{{computer.UnitofPrice}}</td>
Typescript code for form control validation
public frmCtrl: FormControl = new FormControl('', this.customValidator());
customValidator() {
return (control: AbstractControl): { [key: string]: boolean } | null => {
if ((!control.value)) {
return { 'textRequired': true };
}
return null;
};
}
The current implementation validates empty textboxes. How can I modify the custom validator function to validate only based on the "Optional" property of the computer list? Any suggestions would be appreciated.