constructor(private stockService: StockService, private fb: FormBuilder, public dialog: MatDialog, public snackBar: MatSnackBar, private supplierService: SupplierService, private productService: ProductService) {
this.stockForm = this.fb.group ({ //form validator for create and update
_id: [ "" ],
stockItem: this.fb.array([ this.createItem() ])
});
}
createItem(): FormGroup { //form array for order Items
return this.fb.group({
supplierId: [ "", Validators.compose([Validators.required, Validators.pattern(/^[a-f\d]{24}$/i), Validators.minLength(24), Validators.maxLength(24)]) ],
productId: [ "", Validators.compose([Validators.required, Validators.pattern(/^[a-f\d]{24}$/i), Validators.minLength(24), Validators.maxLength(24)]) ],
productQuantity: [ "", Validators.compose([Validators.required, Validators.pattern(/^[0-9]\d*$/), Validators.min(1), Validators.max(99999)]) ]
});
}
i'm seeking to monitor changes in individual elements within a form array. I currently have code that observes all elements in the form array for changes.
onChanges(): void {
this.stockForm.get('stockItem').valueChanges.subscribe(val => {
});
}