How to prevent ionic keyboard from hiding

2019-07-31 04:22发布

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条回答
何必那么认真
2楼-- · 2019-07-31 05:10

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!

查看更多
登录 后发表回答