NG-更改后角指令数据绑定情况 [英] angular directive data binding happens after ng-change
问题描述
大家好,我尝试一些东西。
Guys I'm experimenting something.
<input my-checkbox type="checkbox" ng-model="object.isChecked" ng-change="triggerChange()" ng-click="triggerClick()">
指令我-复选框(写在CoffeeScript中)
angular.module('myApp')
.directive('myCheckbox', ()->
return {
restrict: 'A'
replace: true,
template: """
<div>
<input type="checkbox" ng-model="ngModel" ng-change="ngChange()" ng-click="ngClick()">
</div>
"""
scope: {
ngChange: "&"
ngClick: "&"
ngModel: "="
}
}
)
观察
当您选中该复选框,功能triggerChange()火灾,但object.isChecked值不会改变。然后函数object.isChecked价值变动triggerClick()火灾。
Observation
When you check the checkbox, function triggerChange() fires but, object.isChecked value doesn't change. Then function triggerClick() fires with object.isChecked value changes.
我想知道,这是真的,数据绑定NG-更改后=发生了什么?
I'm wondering, is it true, the data binding "=" happens after ng-change?
推荐答案
请参阅: ngModelOptions
允许调整模型更新的方式进行。使用的 ngModelOptions 的可以指定事件的自定义列表将触发模型更新和/或去抖动延迟,这样,当一个定时器到期实际更新只发生;另一个变化发生后,此计时器将被重置。
Allows tuning how model updates are done. Using ngModelOptions you can specify a custom list of events that will trigger a model update and/or a debouncing delay so that the actual update only takes place when a timer expires; this timer will be reset after another change takes place.
例如,试试这个:
<input type="text" ng-model="term" ng-change="fn(term)" ng-model-options="{debounce: 750}" />
这篇关于NG-更改后角指令数据绑定情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!