I have a page with many inputs, and I want to make it 'readOnly
' I find this solution: How to change HTML element readonly and required attribute in Angular2 Typescript?
But I don't want to do it for every input separately.
How can I add readOnly
property to all inputs in some div.
AngularJS ng-readonly DirectiveThe 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 .
The readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).
Task: Conditionally make input field readonly Add this to Typescript component. // class properties @ViewChild('clubName') inp:HTMLInputElement; // Could also use interface Element // conditionally set in some other methods of class inp. setAttribute('readonly', 'readonly'); inp. removeAttribute('readonly');
Try this in input field:
[readonly]="true"
Hope, this will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With