Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling checkbox with one way binding

Tags:

angularjs

I have one checkbox list. I need to disable all elements which have model value set to false initially. But because of two way binding I have a problem when I deselect one checkbox it becomes disabled. How to solve it?

<div class="item-s" ng-repeat="element in model.elements">
    <input id="element{{$index.toString()}}"
        type="checkbox"
        ng-true-value="true"
        ng-false-value="false"
        ng-model="element.value"
        ng-disabled="!element.value" />
    <label for="element{{$index.toString()}}">{{element.name}}</label>
</div>
like image 542
bambi Avatar asked Apr 14 '15 20:04

bambi


1 Answers

Adding :: in front of a binding expression causes it to only be evaluated once. This should get you what you need:

ng-disabled="::!element.value"

Here's Angular's docs on one-time binding.

like image 76
SethGunnells Avatar answered Sep 30 '22 17:09

SethGunnells