2017-05-09 8 views
0

以下は、ng-clickのコードですクリックイベントを1回だけ行い、ボタンを無効にします。しかし、ボタンタグだけにng-disabledを使う方法(入力タグを使わずに)?ワンクリックでng-disableを使用してボタンを無効にする

初心者の方には本当に感謝しています。

<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="!count && 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> 

答えて

1

あなたは試してみました:

<button ng-click="!count && myFunc()" ng-disabled="count > 0">OK</button> 
+0

をはい、このためにクリックの回のみに制限されています。 –

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

<style> 
.disableButton{ 
Change color of button to #848d95 
} 
</style> 
関連する問題