使用Angular5的ng-bootstrap ngbTypeahead

时间:2018-01-09 23:31:24

标签: angular angular5 ng-bootstrap type-ahead

Angular 5 with .NET(C#)

我正在尝试合并ng-bootstrap提供的Typeahead控件。 以下是要求: - 名为Category的先行控件 - 选择“类别”列表中的一个项目时,应填充另一个控件(子类别)

我怀疑是:

  1. 如何让typeahead接受一个键/值对(或者像一个对象,例如:带有Id,Name作为其属性的Category),以便我可以获得与单击的类别值对应的键。然后,此类别代码将用于填充子类别字段。

    类别

  2. 上面给出的是我正在使用的控件,.ts文件包含以下内容:

    @ViewChild('category') category: NgbTypeahead;
    focus$ = new Subject<string>();
    click$ = new Subject<string>();
    search = (text$: Observable<string>) =>
      text$
      .debounceTime(200).distinctUntilChanged()
      .merge(this.focus$)
      .merge(this.click$.filter(() => !this.category.isPopupOpen()))
      .map(term => (term === '' ? this.categories : this.categories.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10));
    

    通过从api调用中提取Category.Name来填充'categories'字段,该调用实际上返回了具有Name和Id的Category对象。

    目前,我正在获取值,然后在api返回的Category对象中找到与其对应的id。但这会导致维护很多额外的对象。

    一周后开始研究Angular5(Angular)。非常感谢任何投入。

    这是通过参考以下示例完成的: https://ng-bootstrap.github.io/#/components/typeahead/api

0 个答案:

没有答案