javascript - Call Angular-function upon $scope-variable change - Stack Overflow

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

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.

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.

Share Improve this question asked Apr 14, 2015 at 16:46 user3056656user3056656 531 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

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.

we can use $watchGroup in controller of our directive to bind $scope variable changes (bidirectional)

$scope.$watchGroup(['var1','var2'],function () {

});

you can also check this question.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743761501a4502714.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信