我想在其中一个文本字段中实现自动完成。通过下面这个简单的例子,我尝试使用bootstrap typeahead。
https://ng-bootstrap.github.io/#/components/typeahead/examples#basic
然而,我在编译时得到以下错误。
ERROR in C:/Users/eclipse-workspace/c-UI/src/app/send-email/send-email.component.ts (33,24): Property 'length' does not exist on type '{}'.
ERROR in C:/Users/eclipse-workspace/c-UI/src/app/send-email/send-email.component.ts (34,59): Property 'toLowerCase' does not exist on type '{}'.html
  <input type="text" class="form-control"  [ngbTypeahead]="states">component.ts
import { Component} from '@angular/core';
import {debounceTime, distinctUntilChanged, map} from 'rxjs/operators';
const states = ['Alabama', 'Alaska', 'American Samoa'];
export class SendEmailComponent {
  public model: any;
  search = (text$: Observable<string>) =>
  text$.pipe(
  debounceTime(200),
  distinctUntilChanged(),
  map(term => term.length < 2 ? []
    : states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10))
)
  }请帮帮忙。
发布于 2019-11-26 00:58:14
由于term不是字符串,您可以在箭头函数的开头定义它,如下所示:
  map(term => term.length < 2 ? []
    : states.filter((v:string) => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10))
) https://stackoverflow.com/questions/56146347
复制相似问题