Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-disabled not working with $scope variable

I am trying something like this -

<button class="btn btn-lg btn-block btn-section"
     ng-disabled="{{ selectedfruits.length }} < 5" > Show selected fruits</button>

In chrome developers tool the source looks like this

<button class="btn btn-lg btn-block btn-section" 
    ng-disabled="0 < 5">
        Show selected fruits</button>

But the button is not disabled,my controller looks like this -

.controller('fruitSelectorController',
     function ($scope, $rootScope, $timeout) { 
    $scope.fruits = ['a', 'b', 'c', 'd', 'e'];
                $scope.selectedfruits = [];
    });
like image 614
madhur Avatar asked Dec 11 '22 15:12

madhur


2 Answers

You need to write without interpolation {{ }}. It will automatically parse the content and use the expression

ng-disabled="selectedfruits.length < 5"

See the Documentation

like image 111
Suren Srapyan Avatar answered Dec 27 '22 15:12

Suren Srapyan


You should remove the curly braces from ng-disabled. No need evaluate the array in the view HTML. The scope variable automatically evaluated and angular has great feature which is two way binding, so automatically view will be updated.

<button class="btn btn-lg btn-block btn-section" ng-disabled=" selectedfruits.length  < 5" > Show selected fruits</button>
like image 36
kernal lora Avatar answered Dec 27 '22 16:12

kernal lora