0
votes

I am trying to convert an Angular 6 application in a reusable library; here is what I did:

  • created a new Angular workspace
  • created a new Angular library project inside that workspace
  • copied the artifacts from the old application inside the library and adjusted the import statements

When I try to compile the project with "ng build --project=.." I get a lot of these errors: "Property X is private and only accessible within class Y"

I understand the errors and I will correct them but my question is: If I try to build the old application with aot I don't get this error..why?

Thank you!

2

2 Answers

2
votes

In the AOT compile, Angular statically analyzes your code. Using wrong access modifiers is a criteria that lets the AOT compile fail, while the compile succeeds in a build without AOT.

This is the way it is because in the "just in time" mode (which usually is your ng start), Typescript is not being used - ES5 code is being generated, so there's no such concept as a "private" field, and we have no way of enforcing this.

Things that are accessed from a template must be public, since they're being accessed outside of the class instance.

0
votes

The private property is working with specific versions of Typescript. When creating your new Angular workspace, a new typescript version was installed.