在onchange~pregeNg,angular 2中读取p-selectButton中的值

时间:2017-01-12 11:41:38

标签: angular primeng

SelectButton用于使用按钮从列表中选择单个或多个项目。

basedOnModeofTrack(mode){
    // currentTypeMode has value time means it show time dropdown
    console.log(mode);
    this.currentTypeMode = mode;
  }
<p-selectButton name="trackingmode" (onChange)="basedOnModeofTrack()" [options]="trackingmodes" [(ngModel)]="stolenvehicletrack.trackingmode"></p-selectButton>

2 个答案:

答案 0 :(得分:2)

你错过了活动财产

<p-selectButton name="trackingmode" (onChange)="basedOnModeofTrack($event)" [options]="trackingmodes" [(ngModel)]="stolenvehicletrack.trackingmode"></p-selectButton>
你的ts文件中的

public basedOnModeofTrack(obj:any){
    console.log(obj.value);
}

答案 1 :(得分:0)

检查导入

import {SelectButtonModule} from 'primeng/primeng';

使用ngModel定义双向值绑定,selectbutton需要一组选项,其中每个选项应遵循定义标签值属性的SelectItem接口。

查看:

<p-selectButton [options]="cities" [(ngModel)]="selectedCity"></p-selectButton>

JS CODE:

export class SelectButtonDemo {

    types: SelectItem[];

    selectedType: string;

    selectedTypes: string[] = ['Apartment','Studio'];

    constructor() {
        this.types = [];
        this.types.push({label: 'Apartment', value: 'Apartment'});
        this.types.push({label: 'House', value: 'House'});
        this.types.push({label: 'Studio', value: 'Studio'});
    }    
}

this.selectedType正在选择数据。你可以使用this.selectedType来获取它。