1.Angular可使用renderer的invokeElementMethod方法进行focusgit
@ViewChild('myField') public myField: ElementRef; constructor( private renderer: Renderer ) ... this.renderer.invokeElementMethod(this.myField.nativeElement, 'focus');
2.然而在Renderer2是没有invokeElementMethod,但也能够进行以下操做实现focusgithub
constructor( private renderer: Renderer2 ) ... this.renderer.selectRootElement('#my-field').focus();
3.另外一种再为直接的方法就是对element实现focustypescript
@ViewChild('myField') public myField: ElementRef; ... this.myField.nativeElement.focus();