AngularJS:NG-模型时使用jQuery改变绑定不更新 [英] AngularJS : ng-model binding not updating when changed with jQuery
本文介绍了AngularJS:NG-模型时使用jQuery改变绑定不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的HTML:
<input id="selectedDueDate" type="text" ng-model="selectedDate" />
当我键入入禁区,该模型是通过2路绑定机制更新。甜。
When I type into the box, the model is updated via the 2-way-binding mechanism. Sweet.
的然而的,当我通过jQuery ...
However when I do this via JQuery...
$('#selectedDueDate').val(dateText);
它不更新模型。为什么呢?
It doesn't update the model. Why?
推荐答案
角不知道这种变化。对于这一点,你应该叫 $范围。$摘要()
或使 $范围内的变化。$适用()
:
Angular doesn't know about that change. For this you should call $scope.$digest()
or make the change inside of $scope.$apply()
:
$scope.$apply(function() {
// every changes goes here
$('#selectedDueDate').val(dateText);
});
请参阅这以更好地理解的脏检查的
See this to better understand dirty-checking
更新:这里是一个例子。
这篇关于AngularJS:NG-模型时使用jQuery改变绑定不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文