After upgrading from Angular 2 to Angular 4, I noticed that the Renderer
is now deprecated and we should use Renderer2
according to the documentation.
I have been trying to figure out how to call the focus()
method with the new Renderer source, but I can't seem to find a straightforward way to do it.
Previously, I would use:
this.renderer.invokeElementMethod(element, 'focus', []);
What is the updated approach for this?
EDIT
What if I am focusing on an element obtained through QuerySelector
?
For example:
let inputField = document.querySelectorAll('.dialog input');
if (inputField[0]) {
inputField[0].focus();
}
Since the element is acquired via QuerySelector
, the focus()
method does not work directly on it.