From 92da5430e7c8a09e2741377946c195f240fe6fa8 Mon Sep 17 00:00:00 2001 From: Rado Kirov Date: Thu, 20 Aug 2015 16:25:25 -0700 Subject: [PATCH] fix(injector): support getRootInjectors on dehydrated injectors. Closes #3760 --- modules/angular2/src/core/compiler/element_injector.ts | 1 + .../angular2/test/core/compiler/element_injector_spec.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/modules/angular2/src/core/compiler/element_injector.ts b/modules/angular2/src/core/compiler/element_injector.ts index 1795081369..e389e0f1ee 100644 --- a/modules/angular2/src/core/compiler/element_injector.ts +++ b/modules/angular2/src/core/compiler/element_injector.ts @@ -854,6 +854,7 @@ export class ElementInjector extends TreeNode implements Depend getBoundElementIndex(): number { return this._proto.index; } getRootViewInjectors(): ElementInjector[] { + if (!this.hydrated) return []; var view = this._preBuiltObjects.view; var nestedView = view.getNestedView(view.elementOffset + this.getBoundElementIndex()); return isPresent(nestedView) ? nestedView.rootElementInjectors : []; diff --git a/modules/angular2/test/core/compiler/element_injector_spec.ts b/modules/angular2/test/core/compiler/element_injector_spec.ts index e1f7a05d74..53faa26ae5 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.ts +++ b/modules/angular2/test/core/compiler/element_injector_spec.ts @@ -864,6 +864,12 @@ export function main() { var inj = injector(extraBindings); expect(inj.getRootViewInjectors()).toEqual([]); }); + + it("should return an empty array on a dehydrated view", () => { + var inj = injector(extraBindings); + inj.dehydrate(); + expect(inj.getRootViewInjectors()).toEqual([]); + }); }); describe("dehydrate", () => {