【发布时间】:2019-10-02 10:06:18
【问题描述】:
我想在其中一个文本字段中实现自动完成。我正在尝试按照这个简单的示例使用引导输入。
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))
)
}
请帮忙。
【问题讨论】:
-
我试过上面的代码。我没有遇到任何错误?
-
@wentjun 我可以知道你的角度版本吗?
-
我将您的代码复制并粘贴到此处的堆栈闪电战链接之一中:ng-bootstrap.github.io/#/components/typeahead/examples#basic
-
以上链接使用 Angular 7 而我使用 4 。想知道这是否有影响。
-
嗯...它可能!尤其是 RxJS 运算符。我认为在语法方面可能存在一些差异。
标签: angular autocomplete