有带去抖动的输入、“清除”btn(清除输入)和“使用”btn(使用输入值)。 :
<input ng-model="*" ng-model-options="{ debounce: 1000 }" />
为了正确的“清除”btn 工作,使用 $rollbackViewValue() (here)
<button ng-click='formname.$rollbackViewValue();vm.clear()' />
但是什么方法可以用于“使用”btn?火灾如何更改以在点击时应用(在反跳间隔结束之前)?
最佳答案
对于“使用 btn”,请使用 $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>
关于AngularJS:反跳。点击后应用火灾更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35034892/