From e5c6bb4286cb2fa61fa00b297cf15887df375740 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 5 Jan 2017 17:25:41 -0800 Subject: [PATCH] fix(Compiler): fix template binding parsing (`*directive="-..."`) fixes #13800 --- .../src/template_parser/template_parser.ts | 2 +- .../template_parser/template_parser_spec.ts | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/@angular/compiler/src/template_parser/template_parser.ts b/modules/@angular/compiler/src/template_parser/template_parser.ts index c5e0c08f32..78e8f3f1f2 100644 --- a/modules/@angular/compiler/src/template_parser/template_parser.ts +++ b/modules/@angular/compiler/src/template_parser/template_parser.ts @@ -276,7 +276,7 @@ class TemplateParseVisitor implements html.Visitor { templateBindingsSource = attr.value; } else if (normalizedName.startsWith(TEMPLATE_ATTR_PREFIX)) { templateBindingsSource = attr.value; - prefixToken = normalizedName.substring(TEMPLATE_ATTR_PREFIX.length); + prefixToken = normalizedName.substring(TEMPLATE_ATTR_PREFIX.length) + ':'; } const hasTemplateBinding = isPresent(templateBindingsSource); diff --git a/modules/@angular/compiler/test/template_parser/template_parser_spec.ts b/modules/@angular/compiler/test/template_parser/template_parser_spec.ts index 9ef6fe4818..15541a87d5 100644 --- a/modules/@angular/compiler/test/template_parser/template_parser_spec.ts +++ b/modules/@angular/compiler/test/template_parser/template_parser_spec.ts @@ -1323,17 +1323,30 @@ Reference "#a" is defined several times ("
]#a>
}); + it('should work with *... and use the attribute name as property binding name', () => { expect(humanizeTplAst(parse('
', [ngIf]))).toEqual([ - [EmbeddedTemplateAst], [DirectiveAst, ngIf], - [BoundDirectivePropertyAst, 'ngIf', 'test'], [ElementAst, 'div'] + [EmbeddedTemplateAst], + [DirectiveAst, ngIf], + [BoundDirectivePropertyAst, 'ngIf', 'test'], + [ElementAst, 'div'], + ]); + + // https://github.com/angular/angular/issues/13800 + expect(humanizeTplAst(parse('
', [ngIf]))).toEqual([ + [EmbeddedTemplateAst], + [DirectiveAst, ngIf], + [BoundDirectivePropertyAst, 'ngIf', '0 - 1'], + [ElementAst, 'div'], ]); }); it('should work with *... and empty value', () => { expect(humanizeTplAst(parse('
', [ngIf]))).toEqual([ - [EmbeddedTemplateAst], [DirectiveAst, ngIf], - [BoundDirectivePropertyAst, 'ngIf', 'null'], [ElementAst, 'div'] + [EmbeddedTemplateAst], + [DirectiveAst, ngIf], + [BoundDirectivePropertyAst, 'ngIf', 'null'], + [ElementAst, 'div'], ]); }); });