Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Angular-function upon $scope-variable change

I am new to AngularJS and trying to set up a function that gets called upon whenever a variable is changed.

Currently I have a dropdown-menu, with ng-model bound to a $scope.userRating. And I am trying to get a function that gets called immediately when the user changes the value using the dropdown.

I have been looking at $watch, but not quite sure on how to get it to work. I also tried to make a ng-click function on the in the html, but ng-clicks don't seem to trigger.

like image 219
user3056656 Avatar asked Dec 25 '22 20:12

user3056656


1 Answers

You should use $watch . Example-

 $scope.$watch('modalVarible',function(newVal,oldVal){
//do your code
}

Here on the change of variable 'modalVarible' this watch will be called.

like image 92
Anita Avatar answered Jan 05 '23 19:01

Anita