ng-model不触发textinput change事件

时间:2016-05-26 08:40:34

标签: jquery angularjs kendo-ui

我试图将浮动标签添加到原生剑道ui,例如combobox datepicker和dropdownlist。我的团队想要的当前方法是对文本框使用角度元数据,对任何其他输入使用kendo ui

我对某些部分有疑问:(这是主要问题)

<input type="text" ng-model="testmodel" />
<script>
   $("input").change(function(){
       //i want this event to fire even when you change the text input
       //by changing the value of $scope.testmodel
   });
</script>

目前,只有当用户更改按界面输入的文本值时,才会触发更改事件。通过访问angularjs控制器中的$ scope.testmodel来更改输入值不会触发jquery.change事件

2 个答案:

答案 0 :(得分:2)

你可以使用ng-change指令。

 <input type="text" ng-model="testmodel" ng-change="do()" />

答案 1 :(得分:0)

我假设你背后有一个控制器。在这种情况下,如果您只是使用$ scope而不是Controller As语法,那么您将拥有:

$scope.$watch('testmodel', function(newValue, oldValue) {
  // do things in here when it changes
});

尽量避免混合使用jQuery和Angular。它会变得混乱,特别是当应用程序变得更复杂时。

参考:https://docs.angularjs.org/guide/scope

相关问题