Tutorials References Exercises Bootcamps Videos Menu
Sign Up Create Website Get Certified Upgrade

AngularJS ng-readonly Directive


Make the input field readonly:

Readonly: <input type="checkbox" ng-model="all">
<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).


<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.