*带过滤器管道和切片的 ngFor 不起作用
*ngFor with filter pipe and slice doesn't work
我在 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"
但是当我尝试在其中添加一些东西时,它会中断。
像这样应用多个管道:
let admin of admins | slice:0:10 | filter:term
我在 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"
但是当我尝试在其中添加一些东西时,它会中断。
像这样应用多个管道:
let admin of admins | slice:0:10 | filter:term