AngularJS 指令ng-click

元素被点击时调用方法或者表达式:

<!doctype html>
<html ng-app="myApp">
<head>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body>
  
<div ng-controller="CounterController">
  <button ng-click="count = count + 1" ng-init="count=0">
    Increment
  </button>
  count: {{count}}

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

</body>
</html>

 

angular.module('myApp', [])
.controller('CounterController', function($scope) {
  $scope.decrement = function() {
    $scope.count = $scope.count - 1;
  };
});

 

posted @ 2015-10-03 13:24  Byron12345  阅读(266)  评论(0编辑  收藏  举报