ng-click

Description

ng-click calls a method or expression on the scope when the element is clicked.

Example

The following code shows how to ng-click.


<!doctype html>
<html ng-app="myApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head><!--   w  w  w  .  j  ava  2s .  c om-->
<body>

  <div ng-controller="MyController">
    <button ng-click="add()">
      Add
    </button>
    count: {{count}}

    <button ng-click="decrement()">
      Decrement
    </button>
  <div>

  <script>
    angular.module('myApp', [])
    .controller('MyController', function($scope) {
      
      $scope.count = 0;
      $scope.decrement = function() {
        $scope.count = $scope.count - 1;
      };
      $scope.add = function() {
        $scope.count = $scope.count + 1;
      };
      
    })
  </script>

</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Tutorial »




Introduction
Buildin Filters
Buildin Directives