我是角色的新手,我正在使用此库选择选项 - 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
}
答案 0 :(得分:0)
使用ngModelChange
:
[(ngModel)]="model.date" (ngModelChange)="dateChanged($event)"
$event
是新模型的地方。您也可以通过组件中的this.model.date
访问它。