Set focus on an input with Ionic 2

后端 未结 10 2048
被撕碎了的回忆
被撕碎了的回忆 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

    You don't need to import the 'Input' from 'angular/core'.

    Simply:

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

    And answering comment to Ciprian Mocanu:

    It does not work in iOS :(

    It works on iOS -> checked on iPhone 6 PLUS with iOS 10

提交回复
热议问题