Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

AngularJS ng-readonly Directive


Example

Make the input field readonly:

Readonly: <input type="checkbox" ng-model="all">
<br>
<input type="text" ng-readonly="all">
Try it Yourself »

Definition and Usage

The ng-readonly directive sets the readonly attribute of a form field (input or textarea).

The form field will be readonly if the expression inside the ng-readonly attribute returns true.

The ng-readonly directive is necessary to be able to shift the value between true and false. In HTML, you cannot set the readonly attribute to false (the presence of the readonly attribute makes the element readonly, regardless of its value).


Syntax

<input ng-readonly="expression"></input>

Supported by <input> <textarea> elements.


Parameter Values

Value Description
expression An expression that will set the element's readonly attribute if it returns true.