มีลิสส์สองอัน
- ลิสส์อันแรก กำหนดค่าที่ template เลย
- ลิสส์อันที่สอง กำหนดค่าที่ code
src/pages/home/home.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<ion-header> <ion-navbar> <ion-title> Ionic Blank </ion-title> </ion-navbar> </ion-header> <ion-content padding> <p>{{gaming1}}</p> <ion-item> <ion-label>Gaming1</ion-label> <ion-select [(ngModel)]="gaming1"> <ion-option value="nes">NES</ion-option> <ion-option value="n64">Nintendo64</ion-option> <ion-option value="ps">PlayStation</ion-option> <ion-option value="genesis">Sega Genesis</ion-option> <ion-option value="saturn">Sega Saturn</ion-option> <ion-option value="snes">SNES</ion-option> </ion-select> </ion-item> <p>{{gaming2}}</p> <ion-item> <ion-label>Gaming2</ion-label> <ion-select [(ngModel)]="gaming2"> <ion-option *ngFor="let it of myitem" value={{it.id}}>{{it.name}}</ion-option> </ion-select> </ion-item> </ion-content> |
src/pages/home/home.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { gaming1: string; gaming2: string; myitem; constructor(public navCtrl: NavController) { this.myitem = [ { "id": 1, "name": "NES" }, { "id": 2, "name": "Nintendo64" }, { "id": 3, "name": "PlayStation" }, { "id": 4, "name": "Sega" }] } } |
Link