VOOZH about

URL: https://www.geeksforgeeks.org/angular-js/angularjs-ng-readonly-directive/

⇱ AngularJS ng-readonly Directive - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AngularJS ng-readonly Directive

Last Updated : 11 Jul, 2025

The ng-readonly Directive in AngularJS is used to specify the readonly attribute of an HTML element. The HTML element will be readonly only if the expression inside the ng-readonly directive returns true. The ng-readonly directive is required to change the value between true and false. In case, if the readonly attribute is set to false, then the presence of the readonly attribute makes the element readonly, irrespective of its value.

Syntax:

<element ng-readonly="expression"> 
Contents...
</element>

Parameter:

  • expression: It returns true if the expression sets the element's readonly attribute.

This directive is supported by <input>, <textarea> elements.

Example 1: This example uses ng-readonly Directive to enable readonly property. 

Output:

Example 2: This example uses the ng-readonly Directive to enable the readonly property in option list. 

Output:

Comment

Explore