angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Property is private and only accessible within class

Open aslan92 opened this issue 9 years ago • 41 comments

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0 node: 6.9.5 os: linux x64 @angular/common: 2.4.10 @angular/compiler: 2.4.10 @angular/core: 2.4.10 @angular/forms: 2.4.10 @angular/http: 2.4.10 @angular/material: 2.0.0-beta.2 @angular/platform-browser: 2.4.10 @angular/platform-browser-dynamic: 2.4.10 @angular/router: 3.4.10 @angular/cli: 1.0.0 @angular/compiler-cli: 2.4.10

Repro steps.

ng build -prod

The log given by the failure.

ERROR in /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4028,18): Property '_sidenav' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4030,18): Property '_infoSidenav' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4032,18): Property '_owlCarousel' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4034,18): Property '_tree' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4036,18): Property '_ol3Map' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4524,22): Property '_extendedSearchAccordion' is private and only accessible within class 'AppComponent'.

Mention any other details that might be useful.

ng serve works link to the code of the component: http://pastebin.com/p8EFtbFB

aslan92 avatar Mar 24 '17 10:03 aslan92

@iamonuwa Could you please elaborate on how to do that?

deeptiProjects avatar Aug 20 '17 20:08 deeptiProjects

running this command to deploy the app will fix it.. ng build --env=prod

found the solution in github

deeptiProjects avatar Aug 20 '17 23:08 deeptiProjects

ng build --env=prod worked. Seems ng build --env=prod and ng build --prod are not same.

@deeptiProjects can you describe the difference

arun31786 avatar Aug 21 '17 18:08 arun31786

@deeptiProjects @arun31786 with ng build --env=prod you do not achieve AOT compilation, for more details see docs: https://github.com/angular/angular-cli/wiki/build#build-targets-and-environment-files

Original "error" reported is not an error, but normal restriction of AOT at least for versions 2, 4, 5. The variable used in the template needs to be declared as "public". Template is treated as a separate Typescript class.

tytskyi avatar Aug 21 '17 18:08 tytskyi

ng build -prod --aot=false

johnypremanantham avatar Aug 29 '17 13:08 johnypremanantham

@arun31786 Documentation claims those commands are the same:

# these are equivalent
ng build --target=production --environment=prod
ng build --prod --env=prod
ng build --prod

Karasuni avatar Sep 14 '17 09:09 Karasuni

传送门

Hulva avatar Sep 20 '17 08:09 Hulva

Try ng build --prod aot false

iamonuwa avatar Sep 20 '17 09:09 iamonuwa

I have also the same issue!

LeonMtd avatar Nov 17 '17 07:11 LeonMtd

Same issue here after angular 5 update. I don't want to make all properties en methods public.

nielszandsteeg avatar Nov 17 '17 15:11 nielszandsteeg

These links might helpful: https://angular-2-training-book.rangle.io/handout/aot/aot_limitations.html https://github.com/rangle/angular-2-aot-sandbox

samuelkavin avatar Nov 25 '17 17:11 samuelkavin

I used angular 2.4.10 , angular-cli 1.0.6 ,typescript 2.2.1 I got this error when i upgrade angular to 2.4.10 from 2.3.1 and cli to 1.0.6 from 1.0.0-rc.4 it serves but cant build for prod with aot i have solved to build without aot -> "ng build --prod --aot=false"

MstfTkrsln avatar Dec 01 '17 08:12 MstfTkrsln

I used angular 5.0.5 and cli 1.5.5 have same problem too. Many error:

  • Property ... does not exist on type
  • Property ... is private and only accessible within class

So, we can't use "ng build --prod" ?

MrHOY avatar Dec 06 '17 06:12 MrHOY

+1

Property 'nav' (nav is a private instance of a component in constructor) is private and only accessible within class.

Angular 5.1+ CLI: 1.6.3

This errormsg appears when ng build --prod

woteska avatar Dec 31 '17 16:12 woteska

I have several instances of the same injected variable and it's private in some places and public in others, and it's used in some templates as a private variable, yet one module is complaining that it's private, and the rest aren't.

tinyweasel avatar Feb 12 '18 13:02 tinyweasel

+1 it happens with protected as well. I'm not able to make right sense from those keywords then!

nskshared avatar Mar 31 '18 22:03 nskshared

I am using Angular 5 and having the same issue when deploying Jenkins build. The annoying part is it works locally but not when I make a build

rshah9 avatar Apr 24 '18 10:04 rshah9

Changing to public when used in templates worked for me. Not sure why only one module complained though.

tinyweasel avatar Apr 24 '18 10:04 tinyweasel

Same, cannot make a build for production, this is quite annoying. Angular 6.0.7 Angular CLI : 6.0.8 Everything is working fine in development and for a regular build. POO but forced to make everything public ?

P4Thi0ut avatar Aug 07 '18 13:08 P4Thi0ut

I had the same issue. What I understood, the most correct way is to define your variables as public when planning on using them in a template.

With that said I ended up having to change 1000+ properties in my components. In order to do that efficiently I created this python-script: https://github.com/marcus13371337/angular-aot-fixer

Hope that can help some others to speed up the migration from private properties to public properties in your projects!

marcus13371337 avatar Aug 13 '18 15:08 marcus13371337