0

I'm using the autofocus attribute for mdl-textfield, however after navigating to another page and returning to the target page, the focus on mdl-textfield is lost.

I tried this approach: Angular2 - Focusing a textbox on component load.

However it valid only for DOM elements such as .

I undrestood that if i want to get focus after navigating away and returning, I have to do it on ngAfterViewInit() method?

Any help, How can i do that?

Thanks

Community
  • 1
  • 1
Marwane Hcine
  • 31
  • 1
  • 5
  • the MdlTextFieldComponent has a setFocus() method you don't need the native element to set the focus. example: https://github.com/mseemann/angular2-mdl/tree/master/src/demo-app/app/textfield – michael Dec 04 '16 at 22:15
  • Thanks, I figured out how by using setFocus method inside ngAfterViewInit() . Thanks :) – Marwane Hcine Dec 04 '16 at 22:30

0 Answers0