0

I'm using AngularJS and have a switch, I want it to have that if the switch is turned off that my md-input-container is disabled by default. And when I click the switch to on that the md-input-container is enabled again.

What I have right now works a little bit, but when I want to turn the switch off again the md-input-container is still enabled.

My HTML code:

<div class="col-md-2">
  <md-switch ng-click="enabled()">
      Online verkoop
  </md-switch>
</div>

<div class="col-md-2">
    <md-input-container class="md-block">
       <label style="color: #e94e18;">Bezorgkosten (€)</label>
       <input ng-model="bezorgkosten" ng-disabled="disabled">
    </md-input-container>
</div>

Javascript:

//disable switches
$scope.disabled= true;

$scope.enabled = (function(){
    $scope.disabled = false;
});

1 Answer 1

2
$scope.enabled = (function(){
    $scope.disabled = !$scope.disabled;
});

You can even get that function off the scope

<md-switch ng-click="disabled = !disabled">
  Online verkoop
</md-switch>
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.