是否有其他方法可以最小化代码行。
this.addRoeForm.controls.supplierName.setValidators(Validators.required);
this.addRoeForm.controls.fromCurrency.setValidators(Validators.required);
this.addRoeForm.controls.toCurrency.setValidators(Validators.required);
this.addRoeForm.controls.roe.setValidators(Validators.required);
答案 0 :(得分:1)
Object.keys(this.addRoeForm.controls).forEach(key => {
this.addRoeForm.get(key).setValidators([Validators.required]);
});