madhur madhur - 3 months ago 8
Javascript Question

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 = [];
});

Answer

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

ng-disabled="selectedfruits.length < 5"

See the Documentation

Comments