0

I want to update my Angular model based on text input which its value defined by Jquery script. How do I do that?

My Jquery

$("fire").click(function (e) {
      $("#modelChanger").val(1));
});

My DOM :

<input ng-model="data" type="text" id="modelChanger" ng-change="changeIt()"/>

My Angular controller:

$scope.data= 0; // I hope this one change to 1, but it wont
$scope.changeIt =  function(){
   $scope.data++;
}

I know ng-change always work for user directly change the value of any element. Is there other angular directive to solve this one? Any advice guys?

under5hell
  • 997
  • 3
  • 16
  • 40
  • 2
    Why? Why don't you simply use an ng-click on your fire element and use Angular to update the model? – JB Nizet Jun 29 '15 at 08:22
  • perhaps you are looking for $apply/$digest: http://jimhoskins.com/2012/12/17/angularjs-and-apply.html – smnbbrv Jun 29 '15 at 08:22
  • unfortunately, the fire element actually an element created "on-the-fly" by a minified Jquery script. I only can access it by its class but cannot add ng-click directly to it. – under5hell Jun 29 '15 at 08:23
  • @Manish Kr Shukla : thanks. that's what im looking for :) – under5hell Jun 29 '15 at 08:36
  • You should make custom directive with restrict : 'C' , and you can add handler inside link function. You you will hook to "on-the-fly" created element inside angular. And you can easily attach ng-click here. With element.on('click',fn() {}) , or you can replace dom and recompile element with ng-click. – Milos Mosovsky Jun 29 '15 at 19:26

0 Answers0