Skip to content

fix(compiler): report error for property/event bindings on ng-content - #68715

Closed
toha-marko wants to merge 1 commit into
angular:mainfrom
toha-marko:fix/ng-content-binding-error
Closed

toha-marko wants to merge 1 commit into
angular:mainfrom
toha-marko:fix/ng-content-binding-error

Conversation

@toha-marko

Copy link
Copy Markdown

Previously, adding property bindings like [foo]="bar" or event bindings like (click)="handler()" to <ng-content> was silently ignored. These bindings have no effect since ng-content is not a real DOM element. This commit adds a compile-time error to warn the developer.

Fixes #24259

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Adding property/event bindings to <ng-content> is silently ignored by the compiler.

Issue Number: #24259

What is the new behavior?

The compiler now reports an error when property or event bindings are found on <ng-content>.

@pullapprove
pullapprove Bot requested a review from atscott May 13, 2026 12:44
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label May 13, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 13, 2026
@google-cla

google-cla Bot commented May 13, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Previously, adding property bindings like [foo]="bar" or event bindings
like (click)="handler()" to <ng-content> was silently ignored. These
bindings have no effect since ng-content is not a real DOM element.
This commit adds a compile-time error to warn the developer.

Fixes angular#24259
@toha-marko
toha-marko force-pushed the fix/ng-content-binding-error branch from 729212e to f825e73 Compare May 13, 2026 15:51
@atscott

atscott commented May 13, 2026

Copy link
Copy Markdown
Contributor

Minimally, this would require a migration to remove those invalid properties in order to land it. Given that the bug report has no upvotes or activity in almost a decade, I have to question whether this is worth it.

@atscott

atscott commented May 14, 2026

Copy link
Copy Markdown
Contributor

Is this maybe more appropriate as a template diagnostic or eslint? Breaking compilation on something entirely innocuous seems maybe incorrect.

@toha-marko

Copy link
Copy Markdown
Author

Hi @atscott, thanks for the review and for clarifying this!

You are completely right — since these bindings are currently silently ignored, throwing a hard compiler error now would break existing builds, which makes it a breaking change.

Since it's a harmless issue at runtime, breaking the compilation might be an overkill and require unnecessary migration efforts. I'm happy to close this PR and look into contributing a rule to angular-eslint instead.

Before I close it though, do you think implementing this as a template diagnostic in the core compiler is still worth pursuing, or do you feel ESLint is the best place for this kind of check?

@JeanMeche

Copy link
Copy Markdown
Member

Yeah, +1 on a linting rule.

@JeanMeche JeanMeche closed this Aug 16, 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 20, 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 breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding property/event bindings to ng-content should error

3 participants