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)]) ]
});
}
我想注意表单数组中各个元素的变化。我有代码,但它监视所有表单数组的更改。
onChanges(): void {
this.stockForm.get('stockItem').valueChanges.subscribe(val => {
});
}
答案 0 :(得分:0)
我们可以像这样绑定值更改:
_
onChanges(): void {
this.myForm.valueChanges.subscribe(val => {
//DO you stuff
});
}
_
onChanges(): void {
this.myForm.get('FIELD_NAME').valueChanges.subscribe(val => {
});
}
希望这会对您有所帮助。还要传递字段名称而不是表单名称。