mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Added ngFor track by DSO's id directive
This commit is contained in:
16
src/app/shared/ng-for-track-by-id.directive.ts
Normal file
16
src/app/shared/ng-for-track-by-id.directive.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Directive, Host } from '@angular/core';
|
||||
import { NgForOf } from '@angular/common';
|
||||
|
||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
||||
|
||||
@Directive({
|
||||
// tslint:disable-next-line:directive-selector
|
||||
selector: '[ngForTrackById]',
|
||||
})
|
||||
export class NgForTrackByIdDirective<T extends DSpaceObject> {
|
||||
|
||||
constructor(@Host() private ngFor: NgForOf<T>) {
|
||||
this.ngFor.ngForTrackBy = (index: number, dso: T) => (dso) ? dso.id : undefined;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user