From 7f976381d5813e831eca580fe5ddbc57afa08b58 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Mon, 11 May 2015 16:07:25 -0700 Subject: [PATCH] fix(view): fixed ProtoViewFactory to get all property bindings --- .../src/core/compiler/proto_view_factory.js | 12 +++++++++--- .../test/core/compiler/integration_spec.js | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/angular2/src/core/compiler/proto_view_factory.js b/modules/angular2/src/core/compiler/proto_view_factory.js index 506fd0c194..765f7d9495 100644 --- a/modules/angular2/src/core/compiler/proto_view_factory.js +++ b/modules/angular2/src/core/compiler/proto_view_factory.js @@ -116,8 +116,9 @@ export class ProtoViewFactory { var sortedDirectives = ListWrapper.map(elementBinders, b => new SortedDirectives(b.directives, directives)); var variableBindings = this._createVariableBindings(renderProtoView); - var protoLocals = this._createProtoLocals(renderProtoView); + var protoLocals = this._createProtoLocals(variableBindings); var variableNames = this._createVariableNames(parentProtoView, protoLocals); + var protoChangeDetector = this._createProtoChangeDetector(elementBinders, sortedDirectives, componentBinding, variableNames); var protoView = new AppProtoView(renderProtoView.render, protoChangeDetector, variableBindings, protoLocals, variableNames); @@ -128,9 +129,9 @@ export class ProtoViewFactory { return protoView; } - _createProtoLocals(renderProtoView):Map { + _createProtoLocals(varBindings:Map):Map { var protoLocals = MapWrapper.create(); - MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => { + MapWrapper.forEach(varBindings, (mappedName, varName) => { MapWrapper.set(protoLocals, mappedName, null); }); return protoLocals; @@ -141,6 +142,11 @@ export class ProtoViewFactory { MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => { MapWrapper.set(variableBindings, varName, mappedName); }); + ListWrapper.forEach(renderProtoView.elementBinders, binder => { + MapWrapper.forEach(binder.variableBindings, (mappedName, varName) => { + MapWrapper.set(variableBindings, varName, mappedName); + }); + }); return variableBindings; } diff --git a/modules/angular2/test/core/compiler/integration_spec.js b/modules/angular2/test/core/compiler/integration_spec.js index c683ab33d4..6fac87bbf8 100644 --- a/modules/angular2/test/core/compiler/integration_spec.js +++ b/modules/angular2/test/core/compiler/integration_spec.js @@ -365,7 +365,6 @@ export function main() { })); tb.createView(MyComp, {context: ctx}).then((view) => { - expect(view.rawView.locals).not.toBe(null); expect(view.rawView.locals.get('alice')).toBeAnInstanceOf(ChildComp); @@ -373,6 +372,20 @@ export function main() { }) })); + it('should make the assigned component accessible in property bindings', inject([TestBed, AsyncTestCompleter], (tb, async) => { + tb.overrideView(MyComp, new View({ + template: '

{{alice.ctxProp}}

', + directives: [ChildComp] + })); + + tb.createView(MyComp, {context: ctx}).then((view) => { + view.detectChanges(); + + expect(view.rootNodes).toHaveText('hellohello'); // this first one is the component, the second one is the text binding + async.done(); + }) + })); + it('should assign two component instances each with a var-', inject([TestBed, AsyncTestCompleter], (tb, async) => { tb.overrideView(MyComp, new View({ template: '

',