question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component methods must be public for AOT to work when accessed from the template...

See original GitHub issue

Component methods must be public for AOT to work when accessed from the template… IMO its wrong. A component should be able to mark its properties and methods as private and still allow its template full access (AOT or not). Remember this is not just a pure class, its a component and the view is part of it. And just to prove my point, if you can refer to this in a template, and this == the Component / Class, why would you have to mark the methods of the controller / component as public?

Now to make things worse, WebStorm is following this pattern and so it will not allow for refactorting and other helper intelisence as per this PR: https://youtrack.jetbrains.com/oauth?state=%2Fissue%2FWEB-24234#comment=27-1730331

I beg to re-evaluate this as forcing public on all members of a component just to expose it to the view / template will add uncertainty on OOP and the core concept of encapsulation will be forgone 😦

regards

Sean

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
robwormaldcommented, Nov 20, 2016

By definition, they must be public. This isn’t Angular’s opinion or anything.

The psuedo-code version of what’s happening looks like this


//component 
class MyComponent {
  name: string = 'Rob'
}

//generated HostComponent

class GeneratedHostComponent_MyComponent {
  context: MyComponent = new MyComponent();

  detectChangesInternal(){
    this.renderer.setText(this.el1, this.context.name);
  }
}

The generated HostComponent, again, “hosts” the component instance, and accesses its properties from the outside - so its just regular Typescript semantics.

2reactions
mdarefullcommented, Mar 26, 2018

Couldn’t the GeneratedHostComponent just extend the component?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'X' is private and only accessible within class ...
For a given component all its members (methods, properties) accessed by its template must be public in the AOT compilation scenario.
Read more >
Ahead-of-time (AOT) compilation - Angular
AOT compiles HTML templates and components into JavaScript files long before they are served to the client. With no templates to read and...
Read more >
Class extension - Method wrapping and Chain of Command
Protected or public methods of classes, tables, data entities, or forms can be wrapped by using an extension class. The wrapper method must...
Read more >
Angular: Writing AoT-friendly applications | by David - Medium
This article describes development guidelines and instructions how to write AoT-compatible apps with the Angular CLI. It serves supplementary information to the ...
Read more >
Spring Native documentation
There are two main ways to build a Spring Boot native application: ... For example, if you want to use GraalVM CE instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found