Call Angular Function with Jquery

前端 未结 7 1846
遇见更好的自我
遇见更好的自我 2020-12-04 21:59

How to call angular function when data in text box? here is my code

html




        
7条回答
  •  再見小時候
    2020-12-04 22:15

    You can access the scope of an angular element if you have an ID tag attached to the same DOM element as the ng-controller:

    the DOM:

    your controller:

    function mycontroller($scope) {
       $scope.myfunction = function() {
          //do some stuff here
       }
    }
    

    in jquery you do this and it will access that controller and call that function :

    angular.element('#mycontroller').scope().myfunction();
    

    Do remember to call

    angular.element('#mycontroller').scope().$apply() 
    

    if you update a function variable within scope in myfunction, it will not work otherwise (thanks @andersh)

提交回复
热议问题