2

I have a created a new Angular Project using Angular-CLI.

The versions I am using are:

Angular-Cli: 1.0.2

Angular: 4.0.0.

I have added a lot of code in it but now, when I build my project using below command I get bunch of errors

ng build --target=production --env=staging

Errors:

/src/app/views/signup/signup.component.html (21,86): Property 'email' is protected and only accessible within class 'SignUpComponent' and its subclasses.

/src/app/views/signup/signup.component.html (26,80): Property 'password' is protected and only accessible within class 'SignUpComponent' and its subclasses.

Can someone please help me in this regard that how can I remove these errors? The build is successful when I omit --target=production BUT in past I got issue that without specifying target browser cache the old deployment version and user has to delete the browser cache to effect latest changes/deployment.

2 Answers 2

5

Are your email and password properties defined to be private? Are they used in the component's template? Then they need to be changed from private to public.

When you use the Angular CLI's production mode, you automatically get the following:

  • --aot is set to true
  • --output-hashing is set to all (fingerprints assets)
  • --sourcemaps is set to false
  • --extract-css is set to true (makes real css files for global styles, while dev makes .js files as a rebuild optimization)
  • adds service worker if configured in the CLI json
  • replaces process.env.NODE_ENV in modules with the production value (this is needed for some libs, like react)
  • runs uglify on the code

See this for more information: https://github.com/angular/angular-cli/pull/6232

It is the aot compiler that is most likely generating these errors. The aot compiler compiles the template in TypeScript and hence generates more type errors. So another alternative is to use the --prod without aot.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, the email and password are protected in the component's but in previous version of angular-cli/angular it worked. So, should I make them public or use --aot=false?
Make them Public... AOT is necessary for production performance
I'm not sure as to which version of the CLI started to turn --aot to true for production mode. But my guess is that is why it worked previously. And as P. Moloney mentioned ... using --aot=false is not really a good choice because the aot (ahead of time compiler) can improve your startup performance.
2

You cloud try to set public visibility on email and password.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.