定義和用法
在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>
試一試»