简体   繁体   English

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

[英]How to call a function on value change while using ng-selectize?

I am new to angular and I am using this library for select options - https://github.com/NicholasAzar/ng-selectize 我是angular的新手,我正在使用该库来选择选项-https: //github.com/NicholasAzar/ng-selectize

Two-way binding is working but I am not able to call a function when the value is changed. 双向绑定正在工作,但是更改值后无法调用函数。

Here is the code - 这是代码-

signup.component.html 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 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
}

Use ngModelChange : 使用ngModelChange

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

Where $event is the new model. $event是新模型。 You can also access it via this.model.date in the component of course. 您当然也可以通过组件中的this.model.date访问它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何禁用选择或灰色下拉列表的值项目列表中的特定值 (<ng-selectize> 或者<options> ) 在 anguarl 7 - How to disable selection or grey out the for particular value in List of value items of drop down list (<ng-selectize> or <options> ) in anguarl 7 删除在 ng-selectize 上选择的当前元素? - Remove the current element selected on ng-selectize? 如何将npm软件包(ng-selectize)添加和配置为plunker角演示? - How do I add and configure an npm package (ng-selectize) into a plunker angular demo? 对组件类函数的 Angular ng-change 调用不会触发 - Angular ng-change call to a Component Class function not triggering 如何调用更改我的总价值的函数Typescript代码 - How to call function that change my total value Typescript code Angular-使用如何在使用ng-dynamic-component动态创建的组件上调用函数 - Angular - using how to call function on component created dynamically using ng-dynamic-component 使用 ng build --prod 编译时如何更改变量的值? - How can I change the value of a variable when I compile using ng build --prod? ngModel 在 ng-For 中使用时覆盖之前的值 - ngModel Overwrites the previous value while using in ng-For Angular - 使用 ng-template 和 ngTemplateOutlet 时出现值绑定问题 - Angular - Value binding issue while using ng-template and ngTemplateOutlet 如何调用一个函数<ng-template>让变量声明 Angular 4 - How to call a function in <ng-template> let variable declaration Angular 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM