Skip to content

Commit 7f97638

Browse files
committed
fix(view): fixed ProtoViewFactory to get all property bindings
1 parent ac80df0 commit 7f97638

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

modules/angular2/src/core/compiler/proto_view_factory.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ export class ProtoViewFactory {
116116
var sortedDirectives = ListWrapper.map(elementBinders, b => new SortedDirectives(b.directives, directives));
117117

118118
var variableBindings = this._createVariableBindings(renderProtoView);
119-
var protoLocals = this._createProtoLocals(renderProtoView);
119+
var protoLocals = this._createProtoLocals(variableBindings);
120120
var variableNames = this._createVariableNames(parentProtoView, protoLocals);
121+
121122
var protoChangeDetector = this._createProtoChangeDetector(elementBinders, sortedDirectives, componentBinding, variableNames);
122123
var protoView = new AppProtoView(renderProtoView.render, protoChangeDetector, variableBindings, protoLocals, variableNames);
123124

@@ -128,9 +129,9 @@ export class ProtoViewFactory {
128129
return protoView;
129130
}
130131

131-
_createProtoLocals(renderProtoView):Map {
132+
_createProtoLocals(varBindings:Map):Map {
132133
var protoLocals = MapWrapper.create();
133-
MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => {
134+
MapWrapper.forEach(varBindings, (mappedName, varName) => {
134135
MapWrapper.set(protoLocals, mappedName, null);
135136
});
136137
return protoLocals;
@@ -141,6 +142,11 @@ export class ProtoViewFactory {
141142
MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => {
142143
MapWrapper.set(variableBindings, varName, mappedName);
143144
});
145+
ListWrapper.forEach(renderProtoView.elementBinders, binder => {
146+
MapWrapper.forEach(binder.variableBindings, (mappedName, varName) => {
147+
MapWrapper.set(variableBindings, varName, mappedName);
148+
});
149+
});
144150
return variableBindings;
145151
}
146152

modules/angular2/test/core/compiler/integration_spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,27 @@ export function main() {
365365
}));
366366

367367
tb.createView(MyComp, {context: ctx}).then((view) => {
368-
369368
expect(view.rawView.locals).not.toBe(null);
370369
expect(view.rawView.locals.get('alice')).toBeAnInstanceOf(ChildComp);
371370

372371
async.done();
373372
})
374373
}));
375374

375+
it('should make the assigned component accessible in property bindings', inject([TestBed, AsyncTestCompleter], (tb, async) => {
376+
tb.overrideView(MyComp, new View({
377+
template: '<p><child-cmp var-alice></child-cmp>{{alice.ctxProp}}</p>',
378+
directives: [ChildComp]
379+
}));
380+
381+
tb.createView(MyComp, {context: ctx}).then((view) => {
382+
view.detectChanges();
383+
384+
expect(view.rootNodes).toHaveText('hellohello'); // this first one is the component, the second one is the text binding
385+
async.done();
386+
})
387+
}));
388+
376389
it('should assign two component instances each with a var-', inject([TestBed, AsyncTestCompleter], (tb, async) => {
377390
tb.overrideView(MyComp, new View({
378391
template: '<p><child-cmp var-alice></child-cmp><child-cmp var-bob></p>',

0 commit comments

Comments
 (0)