angular - ngbtypeahead angular 4 返回属性“长度”不存在类型“{}”错误
问题描述
我想在其中一个文本字段中实现自动完成。我正在尝试按照这个简单的示例使用引导输入。
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">
组件.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))
)
}
请帮忙。
解决方案
由于 term 不是字符串,您可以在箭头函数的开头定义它,如下所示:
map(term => term.length < 2 ? []
: states.filter((v:string) => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10))
)
推荐阅读
- javascript - InfoWindows 有一些问题。不太确定如何处理它
- google-cloud-data-fusion - 相当于谷歌云数据融合数据管道牧马人中的 LEFT() 函数?
- vim - 无法让 vim 8.0 终端 API 工作到 vim
- asp.net-core - 将接受语言标头复制到传出请求的简便方法?
- tensorflow - 如何训练 tesseract 以减少空输出的数量
- ios - 删除 ionic 3 中的 iOS 滚动反弹
- iphone - 如何将pdf文件传递给php
- javascript - Cordova 应用程序 - 键盘显示/打开之前的事件侦听器
- c++ - 如何在不设置完整路径的情况下访问 C++ 中的资源
- json - 更新 json 列需要太多时间