Skip to content

Instantly share code, notes, and snippets.

@jsayol
Last active December 27, 2016 00:28
Show Gist options
  • Save jsayol/cb622b129772c9f59e2400ac19a25bcf to your computer and use it in GitHub Desktop.
Save jsayol/cb622b129772c9f59e2400ac19a25bcf to your computer and use it in GitHub Desktop.
import {
Directive, TemplateRef, Input, ChangeDetectorRef, ViewContainerRef,
IterableDiffers, OnChanges, SimpleChanges, SimpleChange
} from '@angular/core';
import { NgFor } from "@angular/common";
import { NgForRow } from "@angular/common/src/directives/ng_for";
@Directive({
selector: '[ngFor][ngForIn]'
})
export class NgForIn extends NgFor implements OnChanges {
@Input() ngForIn: any;
constructor(viewContainer: ViewContainerRef,
template: TemplateRef<NgForRow>,
differs: IterableDiffers,
cdr: ChangeDetectorRef) {
super(viewContainer, template, differs, cdr);
}
ngOnChanges(changes: SimpleChanges): void {
if ('ngForIn' in changes) {
this.ngForOf = Object.keys(this.ngForIn);
const currentValue: any[] = Object.keys(changes['ngForIn'].currentValue);
const previousValue: any[] = Object.keys(changes['ngForIn'].previousValue);
changes['ngForOf'] = new SimpleChange(previousValue, currentValue);
super.ngOnChanges(changes);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment