使用管道的角形过滤嘴

问题描述 投票:0回答:1

我正在尝试使用管道过滤Angular中的表的帖子,但是我一直在控制台上遇到此错误:core.js:12689无法绑定到ngForFilter,因为它不是'一个'。

我认为错误在于filter:filterPost,但不知道如何解决。有什么线索吗?

我的html代码如下。

<div class="form-group">
    <label for="exampleFormControlInput1">Busca un reporte</label>
    <input type="text" class="form-control" id="exampleFormControlInput1" name="filterPost" placeholder="Busca.." [(ngModel)]="filterPost">
  </div>
<a *ngFor="let report of All_reports | paginate: { itemsPerPage: 10, currentPage: actualPage }; let i = index; 
filter: filterPost" class="list-group-item list-group-item-action flex-column align-items-start" [routerLink]="['/reporte-admin']" 
routerLinkActive="router-link-active" (click)="onSubmit(report._id)">

    <div class="d-flex w-100 justify-content-between">
        <h5 class="mb-1">Reporte #: {{report._id}}</h5>
        <small>{{i+1}}</small>
    </div>
      <p class="mb-1">Comentario: {{report.comentario}}</p>
      <small class="text-muted">Nombre: {{report.nombre}} {{report.apellido}}</small>
</a>
<br>

这是我的filter.pipe.ts代码:

@Pipe({
  name: 'filter'
})
export class FilterPipe implements PipeTransform {

  transform(value: any, arg: any): any {
    const resultPosts = [];
    for(const report of value){
      if(report._id.indexOf(arg) > -1){
        resultPosts.push(report);
      };
    };
    return resultPosts;
  }

}
html angular pipe ngfor
1个回答
0
投票

我相信你应该做这样的事情

*ngFor="let report of All_reports | paginate: { itemsPerPage: 10, currentPage: actualPage } | filter: filterPost; let i = index;"
© www.soinside.com 2019 - 2024. All rights reserved.