AngularJS Tutorial - Call function from scope in change event








The following code shows how to Call function from scope in change event.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--   w  w w.j ava2s .  c  o m-->
<body ng-app="myApp">
  <div ng-controller="MyCtrl">
    <textarea ng-change="changeFunction()" ng-model="myModel"></textarea>
    <div>{{log}}</div>
</div>
<script type='text/javascript'>

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.log=[];
    $scope.changeFunction=function(){
        $scope.log.push('Called');
    }
}
</script>
</body>
</html>

The code above is rendered as follows: