Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make readonly all inputs in some div in Angular2?

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.

like image 511
Max K Avatar asked Nov 29 '16 10:11

Max K


People also ask

How do you make a Div readonly in angular 8?

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 .

How do you make an input field Uneditable?

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

How do you make a field readonly in typescript?

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');


1 Answers

Try this in input field:

[readonly]="true" 

Hope, this will work.

like image 113
Avnesh Shakya Avatar answered Sep 23 '22 06:09

Avnesh Shakya