Reputation: 21
I am trying to convert a string in an object which is having function a value. like this
for (let i = 0; i < this.dataSource.data.length; i++) {
let control = <FormArray>this.formShipment.controls['User'];
var a;
if (this.dataSource.data[i].active == '1') {
a = true
} else {
a = false
}
var s= { 'custom_value'+i : new FormControl(a) }
let objectValue = this._formBuilder.group(s);
var b = { 'value': objectValue }
control.push(objectValue);
}
So what i have tried is
for (let i = 0; i < this.dataSource.data.length; i++) {
let control = <FormArray>this.formShipment.controls['User'];
var a;
if (this.dataSource.data[i].active == '1') {
a = true
} else {
a = false
}
var k='{ "custom_value'+i+'" : new FormControl(a) }'
var m= JSON.parse(k)
let objectValue = this._formBuilder.group(m);
var b = { 'value': objectValue }
control.push(objectValue);
console.log(objectValue)
}
So please help that how to handle the error in it.
Thanks in Advance!
Upvotes: 2
Views: 349