angular - 在Angular中循环自定义组件时如何使用trackby?
问题描述
我正在寻找trackby:
我*ngFor
的自定义组件循环。这是 angular 提供的示例:
<li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>
但是我正在从一个可观察的对象中循环一个自定义组件列表:
<custom-component *ngFor="let item of (observable$ | async); trackBy: trackByFn"></custom-component>
,
当我尝试这样做时,我在 Angular 编译器中得到一个错误:
Can't bind to 'ngForTrackby' since it isn't a known property of 'custom-component'.
trackby
以这种方式循环自定义组件时有没有办法使用?