I am creating Dynamic Reactive form in Angular. But in the below code level.name is not being accepted as compiler is not allowing to give variable inside the group(). It is only allowing fixed value like - state, city etc instead of level.name variable where level is an object which has name field...
this.countryNextLevelsBeforeMan.forEach(**level** => {
let l2 =<FormArray> this.l1FormGroup2.controls["l2"];
l2.push(this.formBuilder.group({
**level.name** : null --> compilation error on this line as variable not getting allowed
}))
});
Inside the group method I want to give control name as a variable (level.name). In the for loop if level is {"name" : "State" , "id" : 2} then I want to set it like below,
l2.push(this.formBuilder.group({
**State** : null --> No compilation error if we give fixed value
}))
(Instead of 'State' I want it to be dynamically assigned by level.name as level.name can be City, Street etc)
Please help!!!