<div><h2>Menus Data Store</h2><divformArrayName="menus"><div*ngFor="let data of menusDataArray?.controls; let i = index"><inputtype="text"[formControlName]="i"><button(click)="removeFormArrayField('menus', i)"class="delete">Delete</button></div><button(click)="onAddNewFormString('menus')">Add Menus</button></div></div>
// Form ArraymenusDataArray?:FormArray;privateinitDataForm(){this.dataForm=this.fb.group({name:[null,Validators.required],menus:this.fb.array([this.createStringElement()]),});this.menusDataArray=this.dataForm.get('menus')asFormArray;}createStringElement(){returnthis.fb.control('');}onAddNewFormString(formControl:string){(this.dataForm?.get(formControl)asFormArray).push(this.createStringElement());console.log("this.menusDataArray --->",this.menusDataArray);}removeFormArrayField(formControl:string,index:number){letformDataArray:FormArray;switch (formControl){case'menus':{formDataArray=this.menusDataArray;break;}default:{formDataArray=null;break;}}formDataArray?.removeAt(index);}
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)