微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将搜索组件作为可重用组件作为角度元素

如何解决如何将搜索组件作为可重用组件作为角度元素

我想将搜索组件实现为可重用组件,基本上这个搜索组件会在我输入内容调用网络服务。这样它就会在那个 url 中搜索获取数据并显示它。我在 lib 文件夹中制作了这个组件并在 app 组件中使用它,但搜索没有发生,事实上过滤器方法没有在组件中触发。请在下面检查我的组件代码

ngOnInit() {
console.log('input variables are ',this._appId,this._sandBox,this._typeId);
this.bpmService.login().subscribe((data) => {
  console.log('=== Login Success ===');
});
this.filteredOptions = this.myControl.valueChanges
  .pipe(
    startWith(''),debounceTime(10),distinctUntilChanged(),switchMap(val => {
      return this.filter(val);
    })
  );

}

 displayFn(user: Case): any {
    return user && JSON.parse(user.summary).field1 ? JSON.parse(user.summary).field1 : 
     this._cases;
 }

 private filter(val: string): Observable<any[]> {
    console.log('filter value is ',val);
    return this.bpmService.getCases(this._sandBox,this._typeId)
       .pipe(
           map(response => response.filter((element: { summary: string; }) => {
         console.log('Response is ====',response);
            return JSON.parse(element.summary).field1.match(val);
            }))
           );

}

这是我的 HTML

<div class="la-case-search">
  <mat-label>Search within cases</mat-label>
  <div class="la-case-search__input">
    <input type="text" matInput [formControl]="myControl" [matAutocomplete]="auto">
    <mat-icon svgIcon="search"></mat-icon>

  </div>
  <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn" (optionSelected) = "selectedCase($event.option.value)">
    <mat-option *ngFor="let option of filteredOptions | async" [value]="option">
      {{option.summary ? option.summary:''}}
    </mat-option>
  </mat-autocomplete>

</mat-form-field>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。