Solution for FormArray controllers
Initialiser le générateur de formulaires FormArray
formInitilize() {
this.Form = this._formBuilder.group({
formArray: this._formBuilder.array([this.createForm()])
});
}
Créer un formulaire
createForm() {
return (this.Form = this._formBuilder.group({
convertodecimal: ['']
}));
}
Définir des valeurs de formulaire dans Form Controller
setFormvalues() {
this.Form.setControl('formArray', this._formBuilder.array([]));
const control = <FormArray>this.resourceBalanceForm.controls['formArray'];
this.ListArrayValues.forEach((x) => {
control.push(this.buildForm(x));
});
}
private buildForm(x): FormGroup {
const bindvalues= this._formBuilder.group({
convertodecimal: x.ArrayCollection1? parseFloat(x.ArrayCollection1[0].name).toFixed(2) : '' // Option for array collection
// convertodecimal: x.number.toFixed(2) --- option for two decimal value
});
return bindvalues;
}
Thulasiram Virupakshi
la source
var twoPlacedFloat = + parseFloat(yourString).toFixed(2)
pour convertir en flottant