最新的Web开发教程
 

AngularJS NG-点击指令


1增加计数变量,每个按钮被点击时:

<button ng-click="count = count + 1" ng-init="count=0">OK</button>
试一试»

定义和用法

ng-click指令告诉AngularJS点击一个HTML元素时该怎么做。


句法

< element ng-click=" expression "></ element >

所有HTML元素的支持。


参数值

Value Description
expression An expression to execute when an element is clicked.

更多示例

执行一个功能,AngularJS,一个按钮被点击时:

<body ng-app="myApp">

<div ng-controller="myCtrl">
    <button ng-click="myFunc()">OK</button>
    <p>The button has been clicked {{count}} times.</p>
</div>

<script>
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
    $scope.count = 0;
    $scope.myFunc = function() {
        $scope.count++;
    };
}]);
</script>

</body>
试一试»