2017-03-09 9 views
0

私のionic2アプリケーションでは、私はテキストボックスを持っています。今は、そのテキストボックスに値を追加せずにフォームを送信しています。そのとき、「テキストボックスは空ではない」という警告を出しています。 アラート取得時のフォーカスが同じテクスチャボックス内にある必要があります。イオン2の入力フィールドに焦点を合わせる方法は?

+0

http://stackoverflow.com/questions/42576869/angular-2-ionic-2-input-box-focus-function-doesnt -exist/42577709#42577709 –

+0

おかげさまで@ suraj私はthruogh行くよ –

+0

あなたのコードを追加できますか? –

答えて

2
import {Component, Input, ViewChild} from '@angular/core'; 
import {NavController} from 'ionic-angular'; 

@Component({ 
    templateUrl: 'build/pages/home/home.html' 
}) 
export class HomePage { 
    @ViewChild('input') myInput ; 

    constructor(private navCtrl: NavController) { } 

    ionViewLoaded() { 

    setTimeout(() => { 
     this.myInput.setFocus(); 
    },150); 

} 

} 

1)輸入 "入力"、 "ViewChild" と "からNavController"

import {Component, Input, ViewChild} from '@angular/core'; 
import {NavController} from 'ionic-angular'; 

2)テンプレートであなたの入力への参照を作成します。

<ion-input #input> 
@ViewChild('input') myInput ; 

3)トリガフォーカス

ionViewLoaded() { 

    setTimeout(() => { 
     this.myInput.setFocus(); 
    },150); 

} 

4)彼キーボード

あなたのconfig.xmlに次の行を追加します

<preference name="KeyboardDisplayRequiresUserAction" value="false" /> 
関連する問題