Skip to content

Child template can access his parent private members that the child class cannot #71032

Description

@PowerKiKi

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

Following #70188, released in Angular 22.2.0, the template can access private members of its corresponding class. That's fine (although opinions might differ). But the template can also access the private member of the class' parent, which are very much not fine at all.

If the child class (correctly) cannot access the parent class private members, then the child template should not be able to access the parent class private members.

Minimum reproduction:

import { bootstrapApplication } from '@angular/platform-browser';
import { Component, signal } from '@angular/core';

export class Parent {
  private readonly parent = signal('from parent');
}

@Component({
  selector: 'app-root',
  template: `
    <p>Hello, {{ parent() }} - This works since Angular 22.2 and it should not !</p> 
    <p>Hello, {{ child() }}</p>
  `,
})
export class App extends Parent {
  private readonly child = signal('from child');

  constructor() {
    super();
    // console.log(this.parent()); // This still does not work and should never work
  }
}

bootstrapApplication(App);

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-cqy6tagz?file=src%2Fmain.ts

Please provide the exception or error you saw

No exception, but I expect to see something like "Property 'parent' is private and only accessible within class".

Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 22.2.0
Angular           : 22.2.0
Node.js           : 22.22.3
Package Manager   : npm 10.8.2
Operating System  : linux x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.2.0            │ ^22.2.0           │
│ @angular/cli              │ 22.2.0            │ ^22.2.0           │
│ @angular/common           │ 22.2.0            │ ^22.2.0           │
│ @angular/compiler         │ 22.2.0            │ ^22.2.0           │
│ @angular/compiler-cli     │ 22.2.0            │ ^22.2.0           │
│ @angular/core             │ 22.2.0            │ ^22.2.0           │
│ @angular/forms            │ 22.2.0            │ ^22.2.0           │
│ @angular/platform-browser │ 22.2.0            │ ^22.2.0           │
│ @angular/router           │ 22.2.0            │ ^22.2.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 6.0.3             │ ~6.0.2            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compilerIssues related to `ngc`, Angular's template compilergemini-triagedLabel noting that an issue has been triaged by gemini

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions