From ff84c5c4da73e6d8b15e8cfae4fca3d45f3ff118 Mon Sep 17 00:00:00 2001 From: Trotyl Date: Wed, 27 Jun 2018 13:05:56 +0800 Subject: [PATCH] fix(common): properly update collection reference in NgForOf (#24684) closes #24155 PR Close #24684 --- packages/common/src/directives/ng_for_of.ts | 1 + packages/common/test/directives/ng_for_spec.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/common/src/directives/ng_for_of.ts b/packages/common/src/directives/ng_for_of.ts index a3ca619cbd..89cb9c1b2e 100644 --- a/packages/common/src/directives/ng_for_of.ts +++ b/packages/common/src/directives/ng_for_of.ts @@ -182,6 +182,7 @@ export class NgForOf implements DoCheck { const viewRef = >>this._viewContainer.get(i); viewRef.context.index = i; viewRef.context.count = ilen; + viewRef.context.ngForOf = this._ngForOf; } changes.forEachIdentityChange((record: any) => { diff --git a/packages/common/test/directives/ng_for_spec.ts b/packages/common/test/directives/ng_for_spec.ts index 683333d0b6..0935650f7e 100644 --- a/packages/common/test/directives/ng_for_spec.ts +++ b/packages/common/test/directives/ng_for_spec.ts @@ -183,9 +183,12 @@ let thisArg: any; it('should allow of saving the collection', async(() => { const template = - '
  • {{i}}/{{items.length}} - {{item}};
'; + '
  • {{i}}/{{collection.length}} - {{item}};
'; 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;'); }));