【问题标题】:*ngFor with filter pipe and slice doesn't work*ngFor 与过滤管道和切片不起作用
【发布时间】:2020-06-10 21:59:08
【问题描述】:

我在 ngFor 元素中有一个包含搜索字段和用户列表的组件。我的目标是只显示列表中的前 10 个用户。这是html部分:

<div class="admins-box-input">
   <input type="text" [(ngModel)]="term" [ngModelOptions]="{standalone: true}">
   <div class="card-user" *ngFor="let admin of admins | slice:0:10; filter:term">
     <img src="{{admin?.avatar}}" alt="">
     <h2>{{admin?.first_name}} {{admin?.last_name}}</h2>
   </div>
</div>

但我不断收到此错误 - Can't bind to 'ngForFilter' since it isn't a known property of 'div'. ("xt" [(ngModel)]="term" [ngModelOptions]="{standalone: true}"> <div class="card-user" [ERROR ->]*ngFor="let admin of admins | slice:0:10; filter:term"> <img src="{{admin?.avatar}}""): ng:///AppModule/GroupCreateComponent.html@72:37 Property binding ngForFilter not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". (" <input type="text" [(ngModel)]="term" [ngModelOptions]="{standalone: true}"> [ERROR ->]<div class="card-user" *ngFor="let admin of admins | slice:0:10; filter:term"> 任何帮助,将不胜感激。我在这里使用 Ng2SearchPipeModule,这个管道运行良好 - *ngFor="let admin of admins | filter:term" 但是当我尝试在其中添加一些东西时,它会中断。

【问题讨论】:

    标签: angular ngfor


    【解决方案1】:

    像这样应用多个管道:

    let admin of admins | slice:0:10 | filter:term
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      • 2018-02-02
      • 2017-06-09
      • 2019-12-13
      • 2020-01-15
      相关资源
      最近更新 更多