Last active
December 27, 2016 00:28
-
-
Save jsayol/cb622b129772c9f59e2400ac19a25bcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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