首页 > 解决方案 > ngx-bootstrap 字体自动专注于 Internet Explorer 11

问题描述

我正在使用 ngx-bootstrap 字体头和 Angular 6 反应形式控制。它在除 Internet Explorer 11 之外的所有浏览器上都可以正常工作。每当没有选择打字头建议列表选项时,我再次单击在打字头控件上设置的焦点之外。你可以看到同样的问题

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

在这里,我发现反应形式存在同样的问题。

如果有人对此有任何选择,请告诉我。

谢谢,阿莫尔·拉詹斯。

标签: internet-explorerangular-reactive-formsngx-bootstraptypehead

解决方案


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

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);
  }
}


推荐阅读