0
在我的ionic2应用程序中,我有一个文本框,现在我提交的表单没有在该文本框中添加任何值,当时我已提醒“文本框不能为空”。 现在当警报得到紧密的焦点应该在相同的texbox。如何使离子2中的任何输入字段的集中焦点?
在我的ionic2应用程序中,我有一个文本框,现在我提交的表单没有在该文本框中添加任何值,当时我已提醒“文本框不能为空”。 现在当警报得到紧密的焦点应该在相同的texbox。如何使离子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)显示t他的键盘
此行添加到您的config.xml:
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
http://stackoverflow.com/questions/42576869/angular-2-ionic-2-input-box-focus-function-doesnt -exist/42577709#42577709 –
谢谢@suraj我会通过它 –
你可以添加你的代码吗? –