diff --git a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts
index 90985be69ce..f27c5d878d1 100644
--- a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts
+++ b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts
@@ -8233,6 +8233,75 @@ suppress
expect(diags.length).toBe(0);
});
+ it('should not report when there are @let declarations at the root of the control flow node', () => {
+ env.write(
+ 'test.ts',
+ `
+ import {Component} from '@angular/core';
+
+ @Component({
+ selector: 'comp',
+ template: ' ',
+ })
+ class Comp {}
+
+ @Component({
+ imports: [Comp],
+ template: \`
+
+ @if (true) {
+ @let value = 1;
+ {{value}}
+ }
+
+ \`,
+ })
+ class TestCmp {}
+ `,
+ );
+
+ const diags = env.driveDiagnostics();
+ expect(diags.length).toBe(0);
+ });
+
+ it('should report when there are @let declarations and multiple nodes at the root of the control flow node', () => {
+ env.write(
+ 'test.ts',
+ `
+ import {Component} from '@angular/core';
+
+ @Component({
+ selector: 'comp',
+ template: ' ',
+ })
+ class Comp {}
+
+ @Component({
+ imports: [Comp],
+ template: \`
+
+ @if (true) {
+ @let value = 1;
+ {{value}}
+ breaks projection
+ }
+
+ \`,
+ })
+ class TestCmp {}
+ `,
+ );
+
+ const diags = env
+ .driveDiagnostics()
+ .map((d) => ts.flattenDiagnosticMessageText(d.messageText, ''));
+ expect(diags.length).toBe(1);
+ expect(diags[0]).toContain(
+ `Node matches the "[foo]" slot of the "Comp" component, but will ` +
+ `not be projected into the specific slot because the surrounding @if has more than one node at its root.`,
+ );
+ });
+
it('should not report when the component only has a catch-all slot', () => {
env.write(
'test.ts',
diff --git a/packages/compiler/src/typecheck/ops/content_projection.ts b/packages/compiler/src/typecheck/ops/content_projection.ts
index 9df54ae5be3..f6732af269d 100644
--- a/packages/compiler/src/typecheck/ops/content_projection.ts
+++ b/packages/compiler/src/typecheck/ops/content_projection.ts
@@ -14,6 +14,7 @@ import {
ForLoopBlockEmpty,
IfBlock,
IfBlockBranch,
+ LetDeclaration,
Node,
SwitchBlock,
SwitchBlockCaseGroup,
@@ -134,6 +135,11 @@ export class TcbControlFlowContentProjectionOp extends TcbOp {
// Check the number of root nodes while skipping empty text where relevant.
for (const child of node.children) {
+ // `@let` declarations don't render anything so they don't affect content projection.
+ if (child instanceof LetDeclaration) {
+ continue;
+ }
+
// Normally `preserveWhitspaces` would have been accounted for during parsing, however
// in `ngtsc/annotations/component/src/resources.ts#parseExtractedTemplate` we enable
// `preserveWhitespaces` to preserve the accuracy of source maps diagnostics. This means