ionic2 + Angular2 选择列表

ionic2 + Angular2 selection of list

http://ionicframework.com/docs/v2/components/#select

我正在尝试显示 select 选项并捕获 select 离子。我试过从方法、onChanges 甚至在单击时内联,但没有任何效果。

<ion-list>
    <ion-item>
        <ion-label>List </ion-label>
        <ion-select [(ngModel)]="selected" multiple="true" cancelText="Cancel" okText="Okay!">
            <ion-option *ngFor="#row of list;" value="{{row.id}}" (click)="checkSelected(row.id)" checked="{{ gq.isSelected(row.id) }}">{{ row.english_name }}</ion-option>
        </ion-select>
    </ion-item>
</ion-list>

设置页面class

export class SettingPage implements OnChanges{

    selected;
    list = [];

    constructor(private nav:NavController, public gq: gq)
    {
        this.gq
            .list()
            .subscribe(data => this.list.push(data));
    }
    stpSelect() {
        console.log('STP selected');
        console.log(this.selected);

    }
    ngOnChanges(changes) {
        console.log(changes);
    }

    checkSelected (data)
    {
        console.log('test');
        console.log(data);
    }
}

我只想在函数发生变化时从函数中捕获 selected 模型值。

由于 ion-select 组件利用了 ngModel,您可以尝试监听 ngModelChange 事件:

<ion-select [(ngModel)]="selected" multiple="true" cancelText="Cancel" okText="Okay!" (ngModelChange)="doSomething()">
  (...)
</ion-select>