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", () => {