AngularJS ng-readonly directive

Definition and usage

ng-readonly sets the form field (input or textarea) of the attribute's readonly attribute.

If ng-readonly The expression in the attribute returns true, then the form field will be read-only.

ng-readonly The directive is necessary for toggling between true and false values. In HTML, you cannot set the readonly attribute to false (the presence of the readonly attribute makes the element read-only regardless of its value).

Example

Make input fields read-only:

Read-only: <input type="checkbox" ng-model="all">
<br>
<input type="text" ng-readonly="all">

Try It Yourself

Syntax

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

Affected <input>, <textarea> Element Support.

Parameters

Parameters Description
expression If it returns true, it will set the expression of the readonly attribute of the element.