在MapPage.xml中我有ion-searchbar和map。 当点击输入在搜索栏键盘打开时。 现在我想要点击键盘或点击地图键盘将关闭。 我尝试在地图中添加事件点击或事件点击离子内容并调用Keyboard.close()但它不起作用 这是我的MapPage.xml
<ion-content (click)="clickContent()">
<div class="map">
<form action=".">
<ion-searchbar #searchbar placeholder="{{'AreaSearch'|translate}}" [(ngModel)]="searchKey" (search)="searchKeyboard(searchKey)"
[ngModelOptions]="{standalone: true}">
</ion-searchbar>
</form>
<div id="map" #map></div>
</div>
</ion-content>
我尝试了案例:
1:
import { Keyboard } from '@ionic-native/keyboard';
export class MapPage {
constructor(public keyboard: Keyboard){}
}
&#13;
并致电
this.keyboard.close()
&#13;
2:
import { Keyboard } from '@ionic-native/keyboard';
&#13;
并致电
Keyboard.close()
&#13;
3: 添加
declare var google: any;
&#13;
上面的@Component并调用
cordova.plugins.keyboard.close()
&#13;
要调用点击离子内容我添加
clickContent(){
console.log("click content")
// call 1/3 event close keyboard for one case:
// this.keyboard.close()
// Keyboard.close()
// cordovar.plugin.keyboard.close()
}
&#13;
点击地图我添加事件:
map.addListener('click', function() {
console.log("click map")
// call 1/3 event close keyboard for one case:
// Keyboard.close()
// this.keyboard.close()
// cordova.plugin.keyboard.close()
});
&#13;
ionic cordova plugin add ionic-plugin-keyboard
npm install --save @ionic-native/keyboard
&#13;
我用js
做到了
$("#searchbar-input").click(function (event) {
event.stopPropagation();
});
$(".map").click(function () {
setTimeout(function () {
Keyboard.close();
}, 400);
});
&#13;