下面是我的ng-click代碼。我希望點擊事件只發生一次。我正在考慮在最後添加比較運算符,但不確定。請幫助,因爲我是新的角js。ng-click角度js中的點擊函數
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<p>Click the button to run a function:</p>
<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>
</html>
感謝@Karim,它的工作! –
不客氣;) – Karim