Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12171

How to get html element using renderer2 service in angular?

$
0
0

I am trying to get html textbox element using renderer2 service of angular/core to manipulate it.Although my code is not giving any error but it stops executing during execution on the line in which I am trying to get that element.that is -this.renderer.selectRootElement('#0', true).focus();It is also setting up id of that text element as 0 which I am doing in initial lines.

Code begins from here--`private focusOnTextbox(){

const inputElements = this.el.nativeElement.querySelectorAll('input');// Set ID for each input elementinputElements.forEach((element: HTMLElement, index: number) => {    const id = index.toString();    this.renderer.setAttribute(element, 'id', id);});// Focus the input with id '0'this.renderer.selectRootElement('#0', true).focus();}

`


Viewing all articles
Browse latest Browse all 12171

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>