[OK]をクリックこれを試すことができます。
リンク上のベース。あなたのページコンポーネントで、その後
<ion-item>
<ion-label>place</ion-label>
<ion-select [(ngModel)]="selected">
<ion-option value="item" *ngFor="let item of options">
{{item.name}} {{item.price}}</ion-option>
</ion-select>
</ion-item>
<div padding>
<button ion-button (tap)="addOption()" block>Add Option</button>
<button ion-button (tap)="PostSelected()" block> Sync </button>
</div>
HTML
にこのコード
を試すことができます。
import { Http, RequestOptions, Headers } from '@angular/http';
import 'rxjs/Rx';
//first declare your ngModel variable and you post array variable
selected:any;
SelectedArray = [];
addOption(){
this.SelectedArray.push(this.selected);
}
PostSelected(){
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({
headers: headers,
method: "POST"
});
let bodu = JSON.stringify(this.SelectedArray)
let result = this._http.post(link, body, options).timeout(30000);
result.subscribe(data => {
console.log('result sucess',data)
},error=>{
console.log('result error',data)
})
}
UPDATE
addOption(){
let validate = this.SelectedArray.filter(res=>{
return res == this.selected;
});
// if validate length is 0 the new value of this.selected is currently not found on this.SelectedArray so its ok to be push
if(validate.length == 0){
this.SelectedArray.push(his.selected)
}else{
// else do other thing
}
}
私はイオンの選択をするngModelを追加すると、私はいくつかの理由で自分のデータを失います。 – ob1
最初は、選択ボックスが機能し、項目を選択できますが、ページには表示されません。次に、選択ボックスをクリックすると、データがありません。 :また、他の人が同じ問題を抱えていたことが判明しましたが、その解決策は機能していません。 [リンク](https://github.com/ionic-team/ionic/issues/8942) – ob1
私のHTMLページは次のようになります: ' 環境変数 << ion-option * ngFor = "環境の環境を許可する"> {{environment.name} } ' –
ob1