ng bootstrap 4-提前打开焦点

rn16

我使用ng-bootstrap 4(测试版8)。目前,我有这个:

<ng-template #rt let-r="result" let-t="term">
    {{ r.label }}
</ng-template>

<input
        id="typeahead-focus"
        class="form-control"
        [(ngModel)]="model"
        [ngbTypeahead]="search"
        [inputFormatter]="formatter"
        [resultTemplate]="rt"
        (focus)="focus$.next($event.target.value)"
        (click)="click$.next($event.target.value)"
        #instance="ngbTypeahead"
/>

现在,如果用户单击输入元素,我想打开预输入。我怎样才能做到这一点?

this.search = (text$) =>
    text$
        .map(term => (term === '' ? this.items : this.items.filter(v => v.label.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10));

this.formatter = (x: {label: string}) => {
    console.log(x);
    return x.label;
丹尼尔·C。

以下解决方案适用于我:

onFocus事件添加到您的输入搜索中

my.html文件

 <input 
    (focus)="onFocus($event)" 
    type="text" 
    (selectItem)="onItemSelected($event)" 
    [(ngModel)]="myModel" 
    [ngbTypeahead]="search" 
    [resultTemplate]="rt" 
    [inputFormatter]="formatter"/>

my.ts文件

  public onFocus(e: Event): void {
    e.stopPropagation();
    setTimeout(() => {
      const inputEvent: Event = new Event('input');
      e.target.dispatchEvent(inputEvent);
    }, 0);
  }

  search = (text$: Observable<string>) =>
    text$
      .debounceTime(200)
      .distinctUntilChanged()
      .map(term => this.myList
          .filter(v => this.myfilter(term))
          .slice(0, 10));

还可以看看Typeahed:允许搜索焦点#698

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ng-bootstrap-提前输入下拉宽度

ng-bootstrap提前选择对象

在 angular 4 中使用 bootstrap 4 或 ng-bootstrap 组件

堆叠的 ng bootstrap 模式失去焦点

Bootstrap 4 beta npm 依赖与 ng-bootstrap

从Json提取数据以提前进行ng-bootstrap

Bootstrap 4 Modal打开错误

如何使用ng2-bootstrap从Bootstrap 3切换到Bootstrap 4?

ng-bootstrap ngbDropdown无法正常工作Angular 4

ng-bootstrap ngbDropdown在angular 4中不起作用

ng-bootstrap在angular 4中不起作用

Angular + ng-bootstrap-模式:窗口无法打开

如何打开作为子组件的ng-Bootstrap-Modal?

Angular 7 + NG Bootstrap,是否从服务中打开模式?

如何使用angular-cli和ng-bootstrap自定义Bootstrap 4 SCSS变量?

Bootstrap 4 Accordian滚动打开内容?

ng-bootstrap角度过滤器json对象,用于提前输入

从 ng2-select 移动并像选择一样使用 ngx-bootstrap 的提前输入

Angular 2-Ng2-Bootstrap:自定义复杂模板提前实现

angular 2 ng-bootstrap 类型提前组件 - 无法绑定到“ngModel”

无法在 NG 4.4.6 环境中安装 angular-4-data-table-bootstrap-4 包

调用函数以防止因提前输入而失去焦点(Bootstrap UI)

使用多个NG Bootstrap日期选择器时按钮的焦点混乱

在Angular 4项目中安装了ng-bootstrap CSS,但似乎无法正常工作

在 ng-bootstrap 的 NgbAccordion 中添加 D3.js v4 图

导航栏未在使用ng-bootstrap和angular 4的浏览器中呈现

如何实现ng-bootstrap 4表排序,分页和过滤

Angular 2引导程序4和ng-bootstrap

Ng-Bootstrap Datepicker,如何在Angular4中突出显示特定日期