Wednesday, February 14, 2018

Private variables and methods in an Angular 4 component are accessible at the template...

...even if they are not accessible from other classes. This is a big difference between Angular and .NET web forms where the private variables and methods in a code behind would not be accessible at a web form. Also note that a variable or method without an accessibility modifier in TypeScript is public by default not private. If there is no modifier at the signature of a constructor or method then, instead, that variable is scoped to that constructor or method only. You need to explictly use the public keyword at constructor signatures or method signatures if you need a variable to be public, but not so at variables and methods in the component's class.

No comments:

Post a Comment