anaval
anaval

Reputation: 1138

ng-model not firing textinput change event

I'm trying to add floating labels to native kendo ui like combobox datepicker and dropdownlist. The current approach my team wants is to use angular metarial for textboxes and kendo ui for any other inputs

I'm having a problem with some parts:(here is the main problem)

<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>

currently, the change event only fires when the user changes the value of text input by interface. changing the input value by accessing $scope.testmodel in the angularjs controller does not fire the jquery.change event

Upvotes: 0

Views: 437

Answers (2)

Hadi
Hadi

Reputation: 17289

you can use ng-change directive for this.

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

Upvotes: 2

Brian
Brian

Reputation: 5049

I assume you have a controller behind this. In that case, if you are just using $scope and not Controller As syntax, then you would have this:

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

Do try to avoid mixing jQuery and Angular. It can get messy, especially as an app gets more complicated.

Reference: https://docs.angularjs.org/guide/scope

Upvotes: 0

Related Questions