如何在使用ng-selectize时调用函数值更改?

时间:2018-02-28 09:36:35

标签: angular typescript

我是角色的新手,我正在使用此库选择选项 - https://github.com/NicholasAzar/ng-selectize

双向绑定正在运行,但我无法在更改值时调用函数。

这是代码 -

signup.component.html

<ng2-selectize id="date" class="small" name="date" [config]="singleSelectConfig" [options]="dates" placeholder="Date" [(ngModel)]="model.date" required #date="ngModel" ngDefaultControl (change)="updateDate()">
</ng2-selectize>

signup.component.ts

DEFAULT_DROPDOWN_CONFIG: any = {
    highlight: false,
    create: false,
    persist: true,
    plugins: ['dropdown_direction', 'remove_button'],
    dropdownDirection: 'down'
};

SINGLE_SELECT_PRESET_VALUE_CONFIG = Object.assign({}, this.DEFAULT_DROPDOWN_CONFIG, {
    labelField: 'value',
    valueField: 'id',
    searchField: ['value']
});

singleSelectConfig: any = this.SINGLE_SELECT_PRESET_VALUE_CONFIG;

updateDate() {
        // call this function
}

1 个答案:

答案 0 :(得分:0)

使用ngModelChange

[(ngModel)]="model.date" (ngModelChange)="dateChanged($event)"

$event是新模型的地方。您也可以通过组件中的this.model.date访问它。