Skip to content

Commit f8e7a37

Browse files
committed
fix(view): fixed view instantiation to use the component template's change detector when creating BindingPropagationConfig
1 parent c686e7e commit f8e7a37

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ export class ProtoView {
449449
lightDom = strategy.constructLightDom(view, childView, element);
450450
strategy.attachTemplate(element, childView);
451451

452-
bindingPropagationConfig = new BindingPropagationConfig(changeDetector);
452+
bindingPropagationConfig = new BindingPropagationConfig(childView.changeDetector);
453453

454454
ListWrapper.push(componentChildViews, childView);
455455
}

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

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -451,30 +451,57 @@ export function main() {
451451
})
452452
}));
453453

454-
it('should provide binding configuration config to the component', inject([AsyncTestCompleter], (async) => {
455-
tplResolver.setTemplate(MyComp, new Template({
456-
inline: '<push-cmp #cmp></push-cmp>',
457-
directives: [[[PushBasedComp]]]
454+
describe("BindingPropagationConfig", () => {
455+
it("can be used to disable the change detection of the component's template",
456+
inject([AsyncTestCompleter], (async) => {
457+
458+
tplResolver.setTemplate(MyComp, new Template({
459+
inline: '<push-cmp #cmp></push-cmp>',
460+
directives: [[[PushBasedComp]]]
461+
}));
462+
463+
compiler.compile(MyComp).then((pv) => {
464+
createView(pv);
465+
466+
var cmp = view.locals.get('cmp');
467+
468+
cd.detectChanges();
469+
expect(cmp.numberOfChecks).toEqual(1);
470+
471+
cd.detectChanges();
472+
expect(cmp.numberOfChecks).toEqual(1);
473+
474+
cmp.propagate();
475+
476+
cd.detectChanges();
477+
expect(cmp.numberOfChecks).toEqual(2);
478+
async.done();
479+
})
458480
}));
459481

460-
compiler.compile(MyComp).then((pv) => {
461-
createView(pv);
482+
it('should not affect updating properties on the component', inject([AsyncTestCompleter], (async) => {
483+
tplResolver.setTemplate(MyComp, new Template({
484+
inline: '<push-cmp [prop]="ctxProp" #cmp></push-cmp>',
485+
directives: [[[PushBasedComp]]]
486+
}));
462487

463-
var cmp = view.locals.get('cmp');
488+
compiler.compile(MyComp).then((pv) => {
489+
createView(pv);
464490

465-
cd.detectChanges();
466-
expect(cmp.numberOfChecks).toEqual(1);
491+
var cmp = view.locals.get('cmp');
467492

468-
cd.detectChanges();
469-
expect(cmp.numberOfChecks).toEqual(1);
493+
ctx.ctxProp = "one";
494+
cd.detectChanges();
495+
expect(cmp.prop).toEqual("one");
470496

471-
cmp.propagate();
497+
ctx.ctxProp = "two";
498+
cd.detectChanges();
499+
expect(cmp.prop).toEqual("two");
472500

473-
cd.detectChanges();
474-
expect(cmp.numberOfChecks).toEqual(2);
475-
async.done();
476-
})
477-
}));
501+
async.done();
502+
})
503+
}));
504+
});
478505

479506
it('should create a component that injects a @Parent', inject([AsyncTestCompleter], (async) => {
480507
tplResolver.setTemplate(MyComp, new Template({
@@ -673,11 +700,17 @@ class MyDir {
673700
}
674701
}
675702

676-
@Component({selector: 'push-cmp'})
703+
@Component({
704+
selector: 'push-cmp',
705+
bind: {
706+
'prop': 'prop'
707+
}
708+
})
677709
@Template({inline: '{{field}}'})
678710
class PushBasedComp {
679711
numberOfChecks:number;
680712
bpc:BindingPropagationConfig;
713+
prop;
681714

682715
constructor(bpc:BindingPropagationConfig) {
683716
this.numberOfChecks = 0;

0 commit comments

Comments
 (0)