Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {Parser} from '../expression_parser/parser';
import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {isBlank, isPresent} from '../facade/lang';
import {Identifiers, identifierToken} from '../identifiers';
import * as html from '../ml_parser/ast';
import {HtmlParser, ParseTreeResult} from '../ml_parser/html_parser';
import {expandNodes} from '../ml_parser/icu_ast_expander';
import {InterpolationConfig} from '../ml_parser/interpolation_config';
import {mergeNsAndName, splitNsName} from '../ml_parser/tags';
import {Identifiers, identifierToken} from '../identifiers';
import {ParseError, ParseErrorLevel, ParseSourceSpan} from '../parse_util';
import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer';
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
Expand All @@ -32,6 +32,7 @@ import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventA
import {PreparsedElementType, preparseElement} from './template_preparser';



// Group 1 = "bind-"
// Group 2 = "var-"
// Group 3 = "let-"
Expand Down
8 changes: 1 addition & 7 deletions modules/@angular/core/src/linker/template_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/

import {isBlank} from '../facade/lang';
import {AppElement} from './element';
import {ElementRef} from './element_ref';
import {AppView} from './view';
import {EmbeddedViewRef} from './view_ref';

const EMPTY_CONTEXT = new Object();

/**
* Represents an Embedded Template that can be used to instantiate Embedded Views.
*
Expand Down Expand Up @@ -51,10 +48,7 @@ export class TemplateRef_<C> extends TemplateRef<C> {
createEmbeddedView(context: C): EmbeddedViewRef<C> {
var view: AppView<C> = this._viewFactory(
this._appElement.parentView.viewUtils, this._appElement.parentInjector, this._appElement);
if (isBlank(context)) {
context = <any>EMPTY_CONTEXT;
}
view.create(context, null, null);
view.create(context || <any>{}, null, null);
return view.ref;
}

Expand Down
36 changes: 36 additions & 0 deletions modules/@angular/core/test/linker/integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,27 @@ function declareTests({useJit}: {useJit: boolean}) {
});
}));

it('should not share empty context for template directives - issue #10045',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp, new ViewMetadata({
template:
'<template pollutedContext let-foo="bar">{{foo}}</template><template noContext let-foo="bar">{{foo}}</template>',
directives: [PollutedContext, NoContext]
}))

.createAsync(MyComp)
.then((fixture) => {

fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('baz');

async.done();
});
}));

it('should not detach views in ViewContainers when the parent view is destroyed.',
inject(
[TestComponentBuilder, AsyncTestCompleter],
Expand Down Expand Up @@ -2303,6 +2324,21 @@ class SomeViewport {
}
}

@Directive({selector: '[pollutedContext]'})
class PollutedContext {
constructor(private tplRef: TemplateRef<any>, private vcRef: ViewContainerRef) {
const evRef = this.vcRef.createEmbeddedView(this.tplRef);
evRef.context.bar = 'baz';
}
}

@Directive({selector: '[noContext]'})
class NoContext {
constructor(private tplRef: TemplateRef<any>, private vcRef: ViewContainerRef) {
this.vcRef.createEmbeddedView(this.tplRef);
}
}

@Pipe({name: 'double'})
class DoublePipe implements PipeTransform, OnDestroy {
ngOnDestroy() {}
Expand Down