首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngx-bootstrap typehead在internet explorer 11上自动聚焦

ngx-bootstrap typehead在internet explorer 11上自动聚焦
EN

Stack Overflow用户
提问于 2019-04-20 19:24:10
回答 1查看 410关注 0票数 1

我正在使用ngx-bootstrap typehead和angular 6 reactive form控件。它在除了internet explorer 11之外的所有浏览器上都工作得很好。每当没有选择typehead建议列表的选项时,我都会再次单击焦点之外的typehead控件。您可以在以下位置看到相同的问题

https://valor-software.com/ngx-bootstrap/#/typeahead#reactive-forms

在这里,我已经确定了反应式表单的相同问题。

如果有人对此有任何选择,请让我知道。

谢谢阿莫尔·拉吉汉斯。

EN

回答 1

Stack Overflow用户

发布于 2019-09-16 11:57:05

我在IE中遇到了同样的行为,并创建了一个快速解决方法。

代码语言:javascript
复制
import { Directive, Input } from '@angular/core';
import { TypeaheadDirective } from 'ngx-bootstrap';
const isIE = navigator.userAgent.indexOf('MSIE')!==-1 || navigator.appVersion.indexOf('Trident/') > -1;


@Directive({selector: '[typeaheadIeFix]', exportAs: 'bs-typeahead'})
export class TypeaheadIeFixDirective extends TypeaheadDirective {
  private ie_init:boolean = false;
  @Input('typeaheadIeFix') typeahead: any;
  /**
   * when ngModel or formControl is init'ed, it seems to update input value triggering an 'input' event in IE.
   * that 'input' event then causes typeahead directive to focus on the bound input and even open its suggestion list if possible. 
   */
  onInput (e) {
    if (isIE && !this.ie_init) {
      this.ie_init = true;
      return;
    }
    super.onInput(e);
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55773043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档