Skip to content

fix(compiler): report unclaimed property bindings on ng-template - #70345

Closed
tso1158687 wants to merge 1 commit into
angular:mainfrom
tso1158687:fix/ng-template-unclaimed-inputs
Closed

tso1158687 wants to merge 1 commit into
angular:mainfrom
tso1158687:fix/ng-template-unclaimed-inputs

Conversation

@tso1158687

Copy link
Copy Markdown

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

Property bindings on a literal <ng-template> element that are not claimed by any directive are never checked against the DOM schema during template type checking. Forgetting to import the directive in

@Directive({selector: 'ng-template[auiTypedOption]'})
export class TypedOptionDirective { auiTypedOption = input.required<any>(); }

@Component({imports: [], template: `<ng-template [auiTypedOption]="searchResult()"></ng-template>`})
export class TestComponent {}

compiles silently and only fails at runtime with NG0303, while the same binding on a <div> is reported as NG8002 at build time.

Issue Number: #69322

What is the new behavior?

A literal <ng-template> (tagName === 'ng-template') is treated like a regular element for the purpose of unclaimed inputs in the type-check block, so the missing import is reported as NG8002: Can't bind to 'auiTypedOption' since it isn't a known property of 'ng-template'. Bindings claimed by a matching directive (e.g. [ngTemplateOutlet], [ngIf]) are not reported. Synthetic Template nodes generated for structural directive shorthand are not affected, since their bindings are already checked on the wrapped element.

The shared fixture in template_mapping_spec.ts now also claims [ngIf]/[ngForOf] (and defines showMessage()), because the <ng-template [ngIf]> / <ng-template ngFor [ngForOf]> source-mapping scenarios relied on those bindings never being checked.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Templates that previously compiled with an unclaimed binding on <ng-template> (and then failed at runtime) now get a build-time diagnostic, consistent with regular elements. Unclaimed output bindings on <ng-template> are intentionally left as-is since they are outside the scope of the issue.

Verified locally with //packages/compiler-cli/src/ngtsc/typecheck/test:test (the new test fails without the change), //packages/compiler-cli/test/ngtsc:ngtsc and //packages/language-service/test:test.

🤖 Generated with Claude Code

Property bindings on a literal <ng-template> element that were not
claimed by any directive were never checked against the DOM schema
during template type checking, so forgetting to import the directive
compiled silently and only failed at runtime with NG0303.

Treat a literal <ng-template> the same way as a regular element for the
purpose of unclaimed inputs, so a missing import is reported as NG8002
at build time. Synthetic template nodes generated for structural
directive shorthand are not affected, since their bindings are checked
on the wrapped element.
@pullapprove
pullapprove Bot requested a review from JoostK August 23, 2026 04:00
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Aug 23, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 23, 2026
@SkyZeroZx

Copy link
Copy Markdown
Contributor

This is a duplicate of #69640

@JeanMeche JeanMeche closed this Aug 23, 2026
@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants