Angular - bind public/private properties

Viewed 1136

I'm doing angular tutorial at angular.io, where I read:

constructor(**public** messageService: MessageService) {}

The messageService property must be public because you're about to bind to it in the template.

Angular only binds to public component properties.

I emphasize public there.

However, if I change public to private there, everything works as before...

So please guide me to place where I can dispel my doubts.

My Angular version: 5.0.0,

Thank you!

3 Answers

This is just a recommendation so that your project is compatible with AOT (Ahead Of Time) type build process. You can see its impact by creating an AOT build with this command:

ng build --prod

If you used Angular CLI to build your application, at some version CLI would swallow the errors that Angular would throw when building an app. With the CLI update they started showing the errors to the user eventually and stopping the application from building successfully.

Check this issue on GitHub for more information.

Yes you're right, but in production mode you can't change public to private.

this show the error in production mode

Related