Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 - Access HTML elements in Typescript using FormControlName

I want to access HTML elements in typescript using FormcontrolName.

I can able to access html element using ID of elements

For example :

var element = document.getElementById("txtID")

But can we access the element using FormControl (without use of ID)

like image 388
Pravin Avatar asked Sep 14 '26 17:09

Pravin


1 Answers

Use QuerySelector of HTML5.

If your html input tag is like this:

<input type="text" id="txtID" formControlName="txtID" />
var element = document.querySelector("input[formControlName='txtID']");
like image 168
Pavankumar Shukla Avatar answered Sep 16 '26 07:09

Pavankumar Shukla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!