Skip to content

Commit 3fec279

Browse files
authored
fix: support *directive on <template> (#9691)
fixes #7315
1 parent 3784696 commit 3fec279

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

modules/@angular/compiler/src/template_parser.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,6 @@ class TemplateParseVisitor implements HtmlAstVisitor {
321321
var hasTemplateBinding = this._parseInlineTemplateBinding(
322322
attr, templateMatchableAttrs, templateElementOrDirectiveProps, templateElementVars);
323323

324-
if (hasTemplateBinding && isTemplateElement) {
325-
this._reportError(
326-
`Can't have template bindings on a <template> element but the '${attr.name}' attribute was used`,
327-
attr.sourceSpan);
328-
}
329-
330324
if (hasTemplateBinding && hasInlineTemplates) {
331325
this._reportError(
332326
`Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with *`,

modules/@angular/compiler/test/template_parser_spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,15 +1153,11 @@ Reference "#a" is defined several times ("<div #a></div><div [ERROR ->]#a></div>
11531153
<ng-content> element cannot have content. <ng-content> must be immediately followed by </ng-content> ("[ERROR ->]<ng-content>content</ng-content>"): TestComp@0:0`);
11541154
});
11551155

1156-
it('should report when *attr is used on a template element', () => {
1157-
expect(() => parse('<template *ngIf>', [])).toThrowError(`Template parse errors:
1158-
Can't have template bindings on a <template> element but the '*ngIf' attribute was used ("<template [ERROR ->]*ngIf>"): TestComp@0:10`);
1159-
});
1156+
it('should treat *attr on a template element as valid',
1157+
() => { expect(() => parse('<template *ngIf>', [])).not.toThrowError(); });
11601158

1161-
it('should report when a template attribute is used on a template element', () => {
1162-
expect(() => parse('<template template="ngIf">', [])).toThrowError(`Template parse errors:
1163-
Can't have template bindings on a <template> element but the 'template' attribute was used ("<template [ERROR ->]template="ngIf">"): TestComp@0:10`);
1164-
});
1159+
it('should treat template attribute on a template element as valid',
1160+
() => { expect(() => parse('<template template="ngIf">', [])).not.toThrowError(); });
11651161

11661162
it('should report when mutliple *attrs are used on the same element', () => {
11671163
expect(() => parse('<div *ngIf *ngFor>', [])).toThrowError(`Template parse errors:

0 commit comments

Comments
 (0)