Set focus on an input with Ionic 2

后端 未结 10 2042
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 00:29

SOLVED :

import { Component, ViewChild} from \'@angular/core\';
import { Keyboard } from \'ionic-native\';


@Component({
  templateUrl: \         


        
10条回答
  •  北海茫月
    2020-12-14 00:54

    import {Component, ViewChild} from '@angular/core';
    import {NavController} from 'ionic-angular';
    
    @Component({
      templateUrl: 'build/pages/home/home.html'
    })
    export class HomePage {
      @ViewChild('Comment') myInput ;
    
      constructor(private navCtrl: NavController) { }
    
      ionViewLoaded() {
    
        setTimeout(() => {
          this.myInput.setFocus();
        },150);
    
     }
    
    }

    Create a reference to your input in your template :
    
    

提交回复
热议问题