i am newbie to angular so i apologize in advance. :)
I am trying to do a reactive forms that adds 2 new forms when i click a button. Till now i succeeded to add only one form when i click the button and i have no idea how to add the second form.
Here is the ts code for one new form
routeForm = this.fb.group({
name: ['', Validators.required],
departureDate: [''],
arrivalDate: [''],
stationsName: this.fb.array([
this.fb.control('')
])
});
get stationsName(){
return this.routeForm.get('stationsName') as FormArray;
}
addNewStationName(){
this.stationsName.push(this.fb.control(''));
}
Here fb is a FormBuilder
And the HTML code
<div formArrayName="stationsName">
<button (click)="addNewStationName()">Add new Station</button>
<div *ngFor="let station of stationsName.controls; let i=index">
<label>Station1 {{i+1}}</label>
<select [formControlName]="i">
<option [ngValue]="null">Select Station</option>
<option *ngFor="let station of responseStations">{{station.name}}</option>
</select>
</div>
</div>
Stationname is the new form (select) that is created when i press the button. I would like that when i pres the button to appear also a form (when i can type a number values) near the select form.
Thank you in advanced!