3

How to Hide Keyboard in ionic3?

We have a problem with ionic 3 apps during testing in iPhone. After fillup Payment Gateway information (which is launched in iFrame), Whenever we go to the back page using the back button, Keyboard is not Hiding.

We used cordova-plugin-ionic-keyboard and use Keyboard.hide() method. But didn't work.

  • Does this answer your question? [Is there any way to hide keyboard when focusing an ion-input?](https://stackoverflow.com/questions/51926420/is-there-any-way-to-hide-keyboard-when-focusing-an-ion-input) – Liam Ferris Jul 26 '20 at 16:21

2 Answers2

2

Using Keyboard plugin for Cordova:

import { Keyboard } from '@ionic-native/keyboard/ngx'; 

...

constructor(private keyboard: Keyboard) { }

...

this.keyboard.show(); 
this.keyboard.hide();

Or if you are using Capacitor (recommended):

import { Plugins, KeyboardInfo } from '@capacitor/core';    
const { Keyboard } = Plugins;

...

Keyboard.show();   
Keyboard.hide();
Juan Antonio
  • 2,451
  • 3
  • 24
  • 34
0

Try this

import { Keyboard } from '@ionic-native/keyboard';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
 constructor(public navCtrl: NavController, public keyboard : Keyboard) {
  }
}

and then on back button use this

this.keyboard.close()
Aniruddh Thakor
  • 1,396
  • 2
  • 9
  • 18