I am doing the migration of an ionic v3 app to ionic v4. I have encountered the problem that when doing the auto-focus on an ion-input the way to do it in ionic v3 does not work, I tried to create a directive to perform the auto-focus, but it has not helped me.
Have you encountered the same problem?
Thanks.
Ionic v3 auto-focus code:
.ts file:
import { ViewChild } from '@angular/core';
@Component({
selector: 'page-inventario',
templateUrl: 'inventario.html'
})
export class InventarioPage{
@ViewChild('inputInventarioCB') CBProductoInventario;
ionViewDidEnter() {
this.focusInput(this.CBProductoInventario);
}
focusInput(input) {
if(this.timer){
clearTimeout(this.timer)
}
this.timer = setTimeout(() => {
input.setFocus();
},1000);
}
}
.html file:
<ion-input #inputInventarioCB type="text" placeholder="Código de barras" required [(ngModel)]="producto.codigoBarras" name="codigoBarras" (keypress)="controlTeclaIntro($event, codigoBarras)"</ion-input>