Set focus on dynamically created input on Angular

后端 未结 2 1411
你的背包
你的背包 2021-01-28 01:51

I\'m dynamically creating inputs with *ngFor. So, I would like to set focus on the last created input. Could someone help me?

This is my

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 02:50

    There are multiple ways to do it but this code is just using template

    U can do it with ngFor last like this

    
    
    
    
    
       
       {{lastOne.focus()}}
    
    
    

    another way to do it like this.

    
    
    
    
    {{lastOne.focus()}}
    
    

    feel free to choose

    https://stackblitz.com/edit/angular-7-master-g3qsmt?file=src%2Fapp%2Fapp.component.html

提交回复
热议问题