2017-10-18 18 views
0

タイトルにはすべてが表示されます。私はIonicで比較的シンプルなハイブリッドアプリケーションをやる必要があり、ボタンを押したときにいくつかのイオン選択で選択された値を取得したい。ここでは、コード行く:リスト内の選択から値を選択する - イオン

page.html

<ion-content padding> 

    <div id="sectionTitle"> </div> 
    <ion-list> 
    <ion-item *ngFor="let question of questions" (click)="itemSelected(question)"> 
     <ion-label>{{question.texto}} </ion-label> 
     <ion-select> 
     <option ng-selected="selected">{{answers[0].texto}}</option> 
     <ion-option text-wrap required *ngFor="let answer of answers; let i = index" onchange="itemSelected(answer)"> 
      <p> {{answer.text}} </p> 
     </ion-option> 
     </ion-select> 
    </ion-item> 
    </ion-list> 

    <div class="sendButton"> 
    <button ion-button full type="submit" (click)="toComparisonPage()"> 
    Send 
<!-- Here is where data must be retrieved --> 
    </button> 
    </div> 
</ion-content> 

page.ts事前に

itemSelected(answer){ 
    console.log("Selected item: "); 
} 

おかげで!!

答えて

0

あなたのタグにngModelを指定します。あなたはその後、パブリック変数を宣言している必要があり、これにアクセスすることができ、あなたのpage.tsで

<ion-select [(ngModel)]="selectedItems"> 

。前回の試行のための

console.log(this.selectedItems);

イオンドキュメントまでより選択設定ヘッド用

https://ionicframework.com/docs/api/components/select/Select/

+0

、私はngModelを指定しなかったが、これらの選択がdynamicaly作成されると、私は彼らがそのngModelを、共有して考えますそれらのうちの1つが変更されると、それらのすべてが自動的に変更されます。S – camnuel

+0

あなたはオブジェクト/配列を持ち、* ngForから適切なインデックスに値を格納できます。 例: '* ngFor ="質問の質問をさせてください。 "i = index"としましょう。 'ng-selected =" selected [i] "' –

関連する問題