diff --git a/modules/angular2/src/core/compiler/change_definition_factory.ts b/modules/angular2/src/core/compiler/change_definition_factory.ts index 1aff05b978..d8a2dede10 100644 --- a/modules/angular2/src/core/compiler/change_definition_factory.ts +++ b/modules/angular2/src/core/compiler/change_definition_factory.ts @@ -58,6 +58,7 @@ class ProtoViewVisitor implements TemplateAstVisitor { visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any { this.boundElementCount++; + templateVisitAll(this, ast.outputs); for (var i = 0; i < ast.directives.length; i++) { ast.directives[i].visit(this, i); } diff --git a/modules/angular2/src/core/compiler/template_ast.ts b/modules/angular2/src/core/compiler/template_ast.ts index facd422a5a..cbe80268cb 100644 --- a/modules/angular2/src/core/compiler/template_ast.ts +++ b/modules/angular2/src/core/compiler/template_ast.ts @@ -77,7 +77,7 @@ export class ElementAst implements TemplateAst { } export class EmbeddedTemplateAst implements TemplateAst { - constructor(public attrs: AttrAst[], public vars: VariableAst[], + constructor(public attrs: AttrAst[], public outputs: BoundEventAst[], public vars: VariableAst[], public directives: DirectiveAst[], public children: TemplateAst[], public ngContentIndex: number, public sourceInfo: string) {} visit(visitor: TemplateAstVisitor, context: any): any { diff --git a/modules/angular2/src/core/compiler/template_parser.ts b/modules/angular2/src/core/compiler/template_parser.ts index 7847b457d3..d1918833a7 100644 --- a/modules/angular2/src/core/compiler/template_parser.ts +++ b/modules/angular2/src/core/compiler/template_parser.ts @@ -223,7 +223,7 @@ class TemplateParseVisitor implements HtmlAstVisitor { this._assertAllEventsPublishedByDirectives(directives, events, element.sourceInfo); this._assertNoComponentsNorElementBindingsOnTemplate(directives, elementProps, element.sourceInfo); - parsedElement = new EmbeddedTemplateAst(attrs, vars, directives, children, + parsedElement = new EmbeddedTemplateAst(attrs, events, vars, directives, children, elementNgContentIndex, element.sourceInfo); } else { this._assertOnlyOneComponent(directives, element.sourceInfo); @@ -241,9 +241,9 @@ class TemplateParseVisitor implements HtmlAstVisitor { element.name, templateElementOrDirectiveProps, templateDirectives); this._assertNoComponentsNorElementBindingsOnTemplate(templateDirectives, templateElementProps, element.sourceInfo); - parsedElement = new EmbeddedTemplateAst([], templateVars, templateDirectives, [parsedElement], - component.findNgContentIndex(templateCssSelector), - element.sourceInfo); + parsedElement = new EmbeddedTemplateAst( + [], [], templateVars, templateDirectives, [parsedElement], + component.findNgContentIndex(templateCssSelector), element.sourceInfo); } return parsedElement; } diff --git a/modules/angular2/test/core/compiler/change_definition_factory_spec.ts b/modules/angular2/test/core/compiler/change_definition_factory_spec.ts index 970eccf577..0aeb2f0e88 100644 --- a/modules/angular2/test/core/compiler/change_definition_factory_spec.ts +++ b/modules/angular2/test/core/compiler/change_definition_factory_spec.ts @@ -90,7 +90,7 @@ export function main() { expect(dispatcher.log).toEqual(['textNode(null)=someValue']); }); - it('should handle events', () => { + it('should handle events on regular elements', () => { var changeDetector = createChangeDetector('
', [], 0); eventLocals.set('$event', 'click'); @@ -98,6 +98,20 @@ export function main() { expect(context.eventLog).toEqual(['click']); }); + it('should handle events on template elements', () => { + var dirMeta = CompileDirectiveMetadata.create({ + type: new CompileTypeMetadata({name: 'SomeDir'}), + selector: 'template', + outputs: ['click'] + }); + var changeDetector = + createChangeDetector('