ユーザ入力の動的リストがあります。ユーザは、入力フィールドを生成する「宛先の追加」をクリックすることにより、宛先を追加することができる。フィールドが生成されると、ユーザーは宛先を入力し、すべての宛先を配列に格納するボタンをクリックします。ユーザーは複数の宛先を追加できるはずです。ionic2/angular2を使用して複数の入力を配列に格納するには
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<form>
<ion-list>
<ion-item>
<ion-label fixed>Starting</ion-label>
<ion-input type="text" ></ion-input>
</ion-item>
<ion-item *ngFor="let destination of destinations" >
<ion-label fixed>Destination</ion-label>
<ion-input type="text" ></ion-input>
</ion-item>
</ion-list>
<button ion-button color="light" icon-right (click)="addDestination()" >
Add Destination
<ion-icon name="add" ></ion-icon>
</button>
<div style="padding-bottom: 10px; position: absolute; bottom: 0px; width: 92%">
<button ion-button block (click)="store()">Find Path</button>
</div>
</form>
</ion-content>
活字体:私は私のコメントで何を意味するか
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public destinations = [];
constructor(public navCtrl: NavController) {
}
addDestination(){
this.destinations.push(1);
console.log(this.destinations);
console.log('hello');
}
store(){
console.log('hello');
console.log(this.destinations);
}
}
ngModelがなる=地[$インデックス]。したがって、各入力には配列の値が保持されています – yBrodsky
はangular2の値ですか? – Dansmith12