Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  57] [ 5]  / answers: 1 / hits: 73736  / 11 Years ago, fri, january 3, 2014, 12:00:00

I have a weird problem with passing a boolean to a text. Here is jsfiddle



<div ng-app ng-controller=MainCtrl>
<p>First Name:
<input ng-model=first ng-readonly=true/>
</p>
<p>Last Name:
<input ng-model=second ng-readonly={{truefalse}}/>
</p>
</div>

function MainCtrl($scope) {
$scope.first = Angular;
$scope.second = JS;
$scope.truefalse = true;
}


Can someone explain me why second field is still modifiable?


More From » angularjs

 Answers
19

You need to pass your scope in ng-readonly without Braces.
And $scope.truefalse shouldn't be a string, so you don't need quotes.



<div ng-app ng-controller=MainCtrl>
<p>First Name:
<input ng-model=first ng-readonly=true/>
</p>
<p>Last Name:
<input ng-model=second ng-readonly=truefalse/>
</p>
</div>

function MainCtrl($scope) {
$scope.first = Angular;
$scope.second = JS;
$scope.truefalse = true;
}

[#73398] Thursday, January 2, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
grayson

Total Points: 36
Total Questions: 113
Total Answers: 95

Location: Tonga
Member since Fri, Aug 21, 2020
4 Years ago
grayson questions
;