constructor(private orderService: OrderService, private fb: FormBuilder, public dialog: MatDialog, public snackBar: MatSnackBar, private productService: ProductService) {
this.orderForm = this.fb.group ({ //form validator for create and update
'_id': [ "" ],
'orderClientName': [ "", Validators.compose([Validators.required, Validators.pattern(/^[a-zA-Z\s]*$/), Validators.minLength(1), Validators.maxLength(50)]) ],
'orderContact': [ "", Validators.compose([Validators.required, Validators.pattern(/^[0-9]*$/), Validators.minLength(11), Validators.maxLength(11)]) ],
'orderItem': this.fb.array([ this.createItem() ]),
'orderDiscount': [ "", Validators.compose([Validators.pattern(/^[0-9]*$/), Validators.minLength(1), Validators.maxLength(20)]) ],
'orderTotal': [ "", Validators.compose([Validators.required, Validators.pattern(/^[0-9]*$/), Validators.minLength(1), Validators.maxLength(5)]) ]
});
}
createItem(): FormGroup {
return this.fb.group({
'productId': [ "", Validators.compose([Validators.required, Validators.pattern(/^[a-f\d]{24}$/i), Validators.minLength(24), Validators.maxLength(24)]) ],
'productPrice': [ "", Validators.compose([Validators.required, Validators.pattern(/^[0-9]\d*$/), Validators.min(1), Validators.max(99999)]) ],
'productQuantity' : [ "", Validators.compose([Validators.required, Validators.pattern(/^[0-9]\d*$/), Validators.min(1), Validators.max(99999)]) ],
});
}
это моя группа форм, и я хочу установить значение productPrice всякий раз, когда происходят изменения в productId.но я не знаю, как установить значение.
getPrice(index){
let a = this.orderForm.value.orderItem[index]['productPrice'].patchValue({productPrice: "12"});
console.log(a);
}
и приведенный выше код не работает.Как это исправить?