AngularJS:去抖动。火灾更改将应用​​于点击

时间:2016-01-27 10:33:49

标签: angularjs

有去抖动输入,'清除'btn(清除输入)和'使用'btn(使用输入值)。 :

<input ng-model="*"  ng-model-options="{ debounce: 1000 }" />

为了正确'清除'btn工作,使用$ rollbackViewValue()(here)

<button ng-click='formname.$rollbackViewValue();vm.clear()' />

但是什么方法可以用于'使用'btn?如何在点击时应用火焰变化(在去抖动间隔结束之前)?

2 个答案:

答案 0 :(得分:2)

对于&#39;使用btn&#39;使用$commitViewValue()

<button ng-click="userForm.userName.$commitViewValue(); setValue()">setValue</button>

只是示例

<form name="userForm">
    <label>Name:
        <input type="text" name="userName"
            ng-model="user.name"
            ng-model-options="{ debounce: 1000 }" />
    </label>
    <button ng-click="userForm.userName.$commitViewValue(); setValue()">setValue</button>

    <button ng-click="userForm.userName.$rollbackViewValue(); user.name=''">Clear</button>
    <br />
</form>

演示http://plnkr.co/edit/EwaNsCcfa72sdnK3REgY?p=preview

答案 1 :(得分:0)

您可以更加具体地使用您的模型选项:

<input ng-model="*"  ng-model-options="{ debounce: { 'default': 1000, 'blur': 0 } }" />

这样,当您单击该按钮时,由于您对输入元素失去焦点,因此去抖超时应该为零。

相关问题