Expression within ng-disabled

2

I have a problem with angle expression

This does not work! ! checked2

<body ng-app="">
    <label>
        Click me to toggle: 
        <input type="checkbox" ng-model="checked"> 
        &nbsp; 
        <input type="checkbox" ng-model="checked2">
    </label>
    <br/>
    <button ng-model="button" ng-disabled="!checked || !checked2">Button</button>
</body> 

So it works checked || checked2

<body ng-app="">
    <label>
        Click me to toggle: 
        <input type="checkbox" ng-model="checked"> 
        &nbsp; 
        <input type="checkbox" ng-model="checked2">
    </label>
    <br/>
    <button ng-model="button" ng-disabled="!checked || !checked2">Button</button>
</body>

I need 2 checkboxes that as I select one of the two, a certain field will be enabled, would that be a bug?

    
asked by anonymous 02.10.2017 / 16:22

3 answers

2

As mentioned by the user Jackson :

  

When a checkbox is checked, it automatically becomes TRUE

The way you did it will only work if one of the two checkboxes is unchecked , because you used the deny token ! before controle and controle2 . What I think you want to do is to put out the (controle || controle2) part, resulting in !(controle || controle2) or re-use ng-checked as you mentioned in the comment.

    
02.10.2017 / 16:50
2

That's right. I'll do booleans for you to understand. NG-Disable output disables the element when its output is True . Home In your doubt for ! (Control1 || control2) would be ! (True || true)

This expression starts with the two FALSE controls, so ... ! (false || false) = > true

If you check one or two, it will disable the button, because ... ! (true || true) = > false ! (false || true) = > false

  

It is the same as math, execute what is inside the parentheses, and then execute what is outside.

    
02.10.2017 / 17:13
1

The directive ng-disabled , if it receives a value false , will release the button, if you receive a value true will lock the button, then your logic can be parsed by a function, which should at the end deny the result, example p>

var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
  $scope.checked = false;
  $scope.checked2 = false;
  $scope.btnStatus = function()
  {
    return !($scope.checked || $scope.checked2);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="app" ng-controller="ctrl">
  <label>
        Click me to toggle: 
        <input type="checkbox" ng-model="checked"> 
        &nbsp; 
        <input type="checkbox" ng-model="checked2">
    </label>
  <br/>
  <button ng-model="button" 
    ng-disabled="btnStatus()">Button</button>
</div>

ng-disabled / a>

    
02.10.2017 / 17:26