Materializecss在Angular 2中多次选择无触发更改

时间:2016-08-29 20:34:47

标签: angular materialize

使用materializecss“多次选择”似乎无法触发change。如何在选择更改时绑定方法。

以下代码不会触发更改。

HTML
<select id="booger" multiple>
    <option value="1">{{articleIdLabel}}</option>
    <option value="2">{{articlePubDateLabel}}</option>
    <option value="3">{{articleTitleLabel}}</option>
    <option value="4">{{articleViewDateLabel}}</option>
</select>
Component
ngAfterViewInit() {
    $("#booger").material_select();
}

change() {
    console.log("change");
}

2 个答案:

答案 0 :(得分:2)

我能够通过对我的代码进行以下更改来解决此问题:

Component
ngAfterViewInit() {
    $("#booger").material_select(this.change.bind(this));
}

change() {
    console.log("change");
}

答案 1 :(得分:0)

使用此代码。它为我工作

<div class="input-field col s12">
    <select formControlName="status" [(ngModel)]="selectedStatus" materialize="material_select">
        <option [ngValue]="" disabled>Select</option>
        <option [ngValue]="1">Enable</option>
        <option [ngValue]="0">Disable</option>
    </select>
    <label>Status</label>
</div>