From 077e0be1e776c987437246c90f4e4603e449e330 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 7 Sep 2016 15:40:00 -0700 Subject: [PATCH] fix(CssSelector): fix `getMatchingElementTemplate()` for void tags fixes #11407 --- modules/@angular/compiler/src/selector.ts | 4 +++- modules/@angular/compiler/test/selector_spec.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/@angular/compiler/src/selector.ts b/modules/@angular/compiler/src/selector.ts index 50df253add..b1408f8e9d 100644 --- a/modules/@angular/compiler/src/selector.ts +++ b/modules/@angular/compiler/src/selector.ts @@ -9,6 +9,7 @@ import {ListWrapper} from './facade/collection'; import {StringWrapper, isBlank, isPresent} from './facade/lang'; +import {getHtmlTagDefinition} from './ml_parser/html_tags'; const _EMPTY_ATTR_VALUE = ''; @@ -101,7 +102,8 @@ export class CssSelector { attrs += ` ${attrName}${attrValue}`; } - return `<${tagName}${classAttr}${attrs}>`; + return getHtmlTagDefinition(tagName).isVoid ? `<${tagName}${classAttr}${attrs}/>` : + `<${tagName}${classAttr}${attrs}>`; } addAttribute(name: string, value: string = _EMPTY_ATTR_VALUE) { diff --git a/modules/@angular/compiler/test/selector_spec.ts b/modules/@angular/compiler/test/selector_spec.ts index 1f3002af34..b6491e4876 100644 --- a/modules/@angular/compiler/test/selector_spec.ts +++ b/modules/@angular/compiler/test/selector_spec.ts @@ -374,5 +374,11 @@ export function main() { expect(template).toEqual(''); }); + + it('should support void tags', () => { + const selector = CssSelector.parse('input[fancy]')[0]; + const template = selector.getMatchingElementTemplate(); + expect(template).toEqual(''); + }); }); }