Angular 2/4 set focus on input element

后端 未结 4 1121
渐次进展
渐次进展 2021-01-07 20:48

How can I set focus on an input by (click) event? I have this function in place but I\'m clearly missing something (angular newbie here)

sTbState: string = \         


        
4条回答
  •  渐次进展
    2021-01-07 21:09

    try this :

    in you HTML file:

    
    
    
     
    

    in your ts File :

    sTbState: string = 'invisible';
    
    toggleSt(e, el) {
      this.sTbState = (this.sTbState === 'invisible' ? 'visible' : 'invisible');
      if (this.sTbState === 'visible') {
        el.focus();
      }
    }
    

提交回复
热议问题