RendererV2 how to focus element ?

276 views
Skip to first unread message

Hengkeat Yam

unread,
Mar 5, 2017, 2:42:49 AM3/5/17
to Angular and AngularJS discussion
hi..all

ng2 we use Renderer
this.renderer.invokeElementMethod(this.el.nativeElement,"focus");

ng 4.0 RendererV2 don have invokeElementMethod, how we focus element ? 

Regards
Yam

Sander Elias

unread,
Mar 6, 2017, 3:21:59 AM3/6/17
to Angular and AngularJS discussion
Hi Yam,

I just checked the source, it's gone, and there is no replacement. 
A quick replacement would be:

if (this.el.nativeElement) { this.el.nativeElement.focus() }

I thnk this would hold in most situations. The only problem I see is that when your app runs in a webworker, but that's pushed down to version 5 anyway.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages