I trying to add a nested drop-down. If we click "Add City", it will create another drop-down. I was successful without drop-down. Please see bellow
..component.html
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<select formControlName="cities">
<option *ngFor="let city of myCities; let i=index" [value]='itemname' >
{{ city }}
</option>
</select>
<br>
<button>Submit</button>
<button (click)="addCity()">Add City</button>
<button (click)="remove(i)">Remove</button>
</form>
component.ts
form = new FormGroup({
cities: new FormControl([null]),
});
myCities = ['Dhaka','Dubai','Munich'];
get cities(): FormArray { return this.form.get('cities') as FormArray; }
addCity() { this.form.get('cities').push(new FormControl())}
remove(index){ this.form.get('cities').removeAt(index) }
Showing error as bellow:
E:/angular/nestedForm2/src/app/order-form/order-form.component.ts (21,39): Property 'push' does not exist on type 'AbstractControl'.
E:/angular/nestedForm2/src/app/order-form/order-form.component.ts (23,42): Property 'removeAt' does not exist on type 'AbstractControl'.
I have tried in different ways but still did not find any solution. Could you please help?
