How to prevent ionic keyboard from hiding

社会主义新天地 提交于 2019-12-11 08:26:14

问题


How can I prevent ionic keyboard from hiding when I press a specific button in my Ionic 1 app?

This solution doesn't work for me, the keyboard remains open wherever I click.


回答1:


A possible solution can be found here (the same link sent by Sahil Dhir). I also had this problem and this solution worked for me.

The directive is:

angular.module('msgr').directive('isFocused', function($timeout) {
  return {
    scope: { trigger: '@isFocused' },
    link: function(scope, element) {
      scope.$watch('trigger', function(value) {
        if(value === "true") {
          $timeout(function() {
            element[0].focus();

            element.on('blur', function() {
              element[0].focus();
            });
          });
        }

      });
    }
  };
});

Its usage is:

<input type="text" is-focused="true">

What it basically does is to watch the focus of the input and whenever the input loses focus (when you press a button on the screen outside the keyboard, for example) it rapidly assigns the focus back to it. So the keyboard doesn't have time to hide.

Hope it works for you too!



来源:https://stackoverflow.com/questions/43585200/how-to-prevent-ionic-keyboard-from-hiding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!