Keyboard.close() is not working in Ionic2


#1

Hi,
I’m trying to close a keyboard when user clear the search bar. This is what I’ve done so far

<ion-col style="padding:0px;" col-90 center>
				<ion-searchbar style="padding:0px;" (ionInput)="getItems($event)"  (ionClear)="onClear($event)"></ion-searchbar>
			</ion-col>

onClear(event){
    console.log('g');
    Keyboard.close();
  }

I’ve used ionic-native for keyboard API. As far as i think, it is supposed to close the keyboard as soon as i click cross button on search bar. The problem is it doesn’t do that! Am I missing something?


#2

Do you see the “g” output in the console?


#3

Yes I see it, the function runs fine but Keyboard.close() doesn’t close the keyboard


#4

Can you try this code?

cordova.plugins.Keyboard.close();


#5

Yes I tried that, I get error while building

[19:05:57]  Error: Error at 
            /Users/abdulwahab/Documents/mobileapps/bytemunch/.tmp/pages/choose-location/choose-location.ts:126:5 
[19:05:57]  Cannot find name 'cordova'. 
[19:05:57]  ngc failed 
[19:05:57]  ionic-app-script task: "build" 
[19:05:57]  Error: Error

#6

declare var cordova; // after import’s