@angular/common#NgForOf TypeScript Examples

The following examples show how to use @angular/common#NgForOf. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: for-track-by-id.directive.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
constructor(
    @Host() @Optional() private ngForOf: NgForOf<T>,
    @Host() @Optional() private cdkForOf: CdkVirtualForOf<T>,
  ) {
    if (this.ngForOf) {
      this.ngForOf.ngForTrackBy = (_index: number, item: T) => item.id;
    } else if (this.cdkForOf) {
      this.cdkForOf.cdkVirtualForTrackBy = (_index: number, item: T) => item.id;
    }
  }
Example #2
Source File: track-by-property.directive.ts    From ng-ant-admin with MIT License 5 votes vote down vote up
public constructor(@Host() @Optional() private readonly _ngFor: NgForOf<any>, @Host() @Optional() private readonly _cdkFor: CdkVirtualForOf<any>) {
    if(this._ngFor){
      this._ngFor.ngForTrackBy = (_: number, item: any) => this._propertyName ? item[this._propertyName] : item;
    }
    if(this._cdkFor){
      this._cdkFor.cdkVirtualForTrackBy = (_: number, item: any) => this._propertyName ? item[this._propertyName] : item;
    }
  }