首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ngbtypeahead 4返回属性'length‘在类型'{}’上不存在错误

ngbtypeahead 4返回属性'length‘在类型'{}’上不存在错误
EN

Stack Overflow用户
提问于 2019-05-15 17:47:53
回答 1查看 425关注 0票数 1

我想在其中一个文本字段中实现自动完成。通过下面这个简单的例子,我尝试使用bootstrap typeahead。

https://ng-bootstrap.github.io/#/components/typeahead/examples#basic

然而,我在编译时得到以下错误。

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
  <input type="text" class="form-control"  [ngbTypeahead]="states">

component.ts

代码语言:javascript
运行
复制
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))
)
  }

请帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2019-11-26 00:58:14

由于term不是字符串,您可以在箭头函数的开头定义它,如下所示:

代码语言:javascript
运行
复制
  map(term => term.length < 2 ? []
    : states.filter((v:string) => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10))
) 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56146347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档