Repository navigation
fix(compiler): report unclaimed property bindings on ng-template - #70345
Closed
tso1158687 wants to merge 1 commit into
Closed
tso1158687 wants to merge 1 commit into
tso1158687 wants to merge 1 commit into
Conversation
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.
Contributor
|
This is a duplicate of #69640 |
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
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 incompiles silently and only fails at runtime with
NG0303, while the same binding on a<div>is reported asNG8002at 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 asNG8002: 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. SyntheticTemplatenodes 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.tsnow also claims[ngIf]/[ngForOf](and definesshowMessage()), 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?
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:ngtscand//packages/language-service/test:test.🤖 Generated with Claude Code