单击Ionic 3中的贴图关闭键盘

时间:2018-01-05 09:24:58

标签: javascript ionic3

在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:

&#13;
&#13;
import { Keyboard } from '@ionic-native/keyboard';
export class MapPage {
 constructor(public keyboard: Keyboard){}
}
&#13;
&#13;
&#13;

并致电

&#13;
&#13;
this.keyboard.close()
&#13;
&#13;
&#13;

2:

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

并致电

&#13;
&#13;
Keyboard.close()
&#13;
&#13;
&#13;

3: 添加

&#13;
&#13;
declare var google: any;
&#13;
&#13;
&#13;

上面的@Component并调用

&#13;
&#13;
cordova.plugins.keyboard.close()
&#13;
&#13;
&#13;

要调用点击离子内容我添加

&#13;
&#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;
&#13;
&#13;

点击地图我添加事件:

&#13;
&#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;
&#13;
&#13;

&#13;
&#13;
ionic cordova plugin add ionic-plugin-keyboard
npm install --save @ionic-native/keyboard
&#13;
&#13;
&#13; 但所有情况都不起作用。一段时间键盘关闭,但之后显示。 我怎么能这样做? Pleasse帮助我! Tkank每个人。

我用js

做到了

&#13;
&#13;
 $("#searchbar-input").click(function (event) {
      event.stopPropagation();
    });

$(".map").click(function () {
      setTimeout(function () {
        Keyboard.close();
      }, 400);

    });
&#13;
&#13;
&#13;

0 个答案:

没有答案