fix(common): properly update collection reference in NgForOf (#24684)

closes #24155

PR Close #24684
This commit is contained in:
Trotyl 2018-06-27 13:05:56 +08:00 committed by Misko Hevery
parent 87ddbdf919
commit ff84c5c4da
2 changed files with 5 additions and 1 deletions

View File

@ -182,6 +182,7 @@ export class NgForOf<T> implements DoCheck {
const viewRef = <EmbeddedViewRef<NgForOfContext<T>>>this._viewContainer.get(i);
viewRef.context.index = i;
viewRef.context.count = ilen;
viewRef.context.ngForOf = this._ngForOf;
}
changes.forEachIdentityChange((record: any) => {

View File

@ -183,9 +183,12 @@ let thisArg: any;
it('should allow of saving the collection', async(() => {
const template =
'<ul><li *ngFor="let item of [1,2,3] as items; index as i">{{i}}/{{items.length}} - {{item}};</li></ul>';
'<ul><li *ngFor="let item of items as collection; index as i">{{i}}/{{collection.length}} - {{item}};</li></ul>';
fixture = createTestComponent(template);
detectChangesAndExpectText('0/2 - 1;1/2 - 2;');
getComponent().items = [1, 2, 3];
detectChangesAndExpectText('0/3 - 1;1/3 - 2;2/3 - 3;');
}));