0

I have the following plunler :

http://plnkr.co/edit/ZJq0Qy3j5nGr1eJ9f9QA?p=preview

What I'd like to do is to enable the button if at least one checkbox is checked.

<button class="btn btn-danger" ng-click="removeSelectedRows()">Remove Selected Rows</button>

This works great :

<button ng-disabled="mySwitch">Click</button>
<input type="checkbox" ng-model="mySwitch">

but when I apply it to my example, it does nothing.

Any advice ?

1 Answer 1

1

Please check this plunk : http://plnkr.co/edit/WpK2KXtAJC3gfl8MoMlZ?p=preview

You can run checks if any of the items in the model is true using $scope.$watch function:

 $scope.$watch('tableSelection', function(val){
    if(val){ //if value is not empty
      $scope.disableRemoveButton = true;
      for (var i in val){ //iterate props of the Object
        if(val.hasOwnProperty(i)){ //only needed props
          if(val[i] == true) { 
          $scope.disableRemoveButton = false;
          }
        }
        }
      }
  }, true)

We also introduce additional flag $scope.disableRemoveButton that is being changed in case if there's true value in model. That corresponds to <button class="btn btn-danger" ng-disabled="disableRemoveButton" in the template.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.