AngularJS Tutorial - Call function from ng-click








The following code shows how to use . Call function from ng-click

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from w  ww.j  a  va2 s .  c om-->
<body ng-app="myApp">
  <div ng-controller="MyCtrl">
    <a ng-click="myName('jz')">Click me</a>
</div>
<script type='text/javascript'>
var myApp = angular.module('myApp',[]);

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
    $scope.myName = function(name) {
         console.log('Hello ' + name);
    }
}
</script>
</body>
</html>

The code above is rendered as follows: