How to use Angular4 to set focus by element id

后端 未结 6 1471
無奈伤痛
無奈伤痛 2020-12-14 14:11

I am new to Angular, and am trying to use it to set focus on an input with the id \"input1\". I am using the following code:



        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 15:12

    This helped to me (in ionic, but idea is the same) https://mhartington.io/post/setting-input-focus/

    in template:

    
          Home
          
    
    
    

    in controller:

      focusInput(input) {
        input.setFocus();
      }
    

提交回复
热议问题