LoginSignup
1
0

More than 5 years have passed since last update.

ng-classでButtonをdisabledにする方法

Posted at

AngularJSがよくわからないので備忘のためにメモ。

今回は、$watchで監視している値が0のとき、ボタンを使えなくする。

スクリプト
$scope.inputValue = function() {
  var total = 0;
  // 0の場合はボタンが押せないようにする
  $scope.test = true;
  if(total > 0){
    $scope.test = false;
  }
  return total;
}

$scope.$watch($scope.inputValue);
テンプレート
<p>値 {{inputValue()}}</p>
<a class="button" ng-class="{disabled: test}">送信</a>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0