[英]How can i store separate data from an FormArray into an normal object array in Angular
這是我的 object 包含數組站,我想在其中存儲來自 routeForm、FormArray“stationsName”的數據(在我通過表單將數據添加到 stationName 數組之后)
Routes = {
name : '',
departureDate: '',
arrivalDate: '',
stations: [{
name: '',
arrival: ''
}]
}
routeForm: FormGroup;
ngOnInit() {
this.routeForm = this.formBuilder.group({
stationsName: new FormArray([])
});
get f() {
return this.routeForm.controls;
}
get stationsName() {
return this.f.stationsName as FormArray;
}
addNewStationName() {
this.stationsName.push(
this.formBuilder.group({
name: ['', []],
arrival: ['', []]
})
);
}
我該怎么做這樣的事情:
this.Routes.stations[0].name = this.routeForm.stationsName[0].name.value
this.Routes.stations[0].arrival = this.routeForm.stationsname[0].arrival.value
ngOnInit() {
this.routeForm = this.formBuilder.group({
stationsName: new FormArray([])
});
this.routeForm.valueChanges.subscribe(data=>{
this.Routes.stations = data.stationsName;
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.