Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOT Compiler requires public properties, while non-AOT allows private properties #37660

Open
cosminadrianpopescu opened this issue Jun 21, 2020 · 1 comment

Comments

@cosminadrianpopescu
Copy link

@cosminadrianpopescu cosminadrianpopescu commented Jun 21, 2020

🚀 feature request

Relevant Package

This feature request is for @angular/core

Description

A clear and concise description of the problem or missing capability...

Here we are, 2 years later, and the Ivy compiler seems to behave in the same way. Still I can't access private properties in templates (or at least protected).

Describe the solution you'd like

If you have a solution in mind, please describe it.

I think the generated class for the View, should extend the factory component class, like this, making it at least possible to access protected properties.

Describe alternatives you've considered

Have you considered any alternative solutions or workarounds?

The alternative is very poor. I have to use a BaseComponent class, so all my components need to extend this class. Then, in the BaseComponent I have a getter, called view, like this:

export class BaseComponent {
  public get view(): any {
    return this;
  }
}
...
\@Component(
...
template: `<div>{{view._name}}</div>
...
) export class MyComponent extends BaseComponent {
  private _name = 'X';
}

I think this is not very optimal.

Did I miss something? Can Ivy compiler in Angular 9 access the private properties in the components?

@Javaman2
Copy link

@Javaman2 Javaman2 commented Jun 22, 2020

I too had to remove all private properties when migrating components to library. A bit odd because the final JavaScript does not have private properties.

Visual Studio Code automatically makes refactored methods private. So this problem is at odds with default VSCode refactoring.

@ngbot ngbot bot added this to the Backlog milestone Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.