-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Guidelines suggest to use protected
for template properties.
#61166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
If I challenge just the idea of pushing But my inner strict persona would say "follow the rule of: use the minimum visibility possible private < protected < public". If my code still works with And on the side note, services are not "template properties" and for services I could see cases where inheritance make more sens. And also you can't use a service function if it's protected :) |
It is not related to inheritance at all. I also never extend components. |
The new style guide has a dedicated entry about this : https://next.angular.dev/style-guide#use-protected-on-class-members-that-are-only-used-by-a-components-template The idea behind this recomendation is that component properties that are only meant to be uses in the templates, should not be exposed as part of the public API of the component. This is why Angular templates have acces to protected properties. |
@JeanMeche thank you for the link I missed that one. But then I think I find an issue because outputs seems to work with |
Uh that's a good find, It should be consistent imho (as in we probably should support protected outputs). |
outputs are part of public API by definition. |
Describe the problem that you experienced
After reviewing google's typescript guidelines (the one that is used as reference for contributing in Angular), it's written that we should use the visibility
protected
in Angular for template properties. https://google.github.io/styleguide/tsguide.html#properties-used-outside-of-class-lexical-scope.But we can agreed that most of the exemples found in Angular's documentation examples use the
public
visibility. (e.g. theadvancedSettings
should be protected https://angular.dev/guide/components/programmatic-rendering#lazy-loading-components)I would be willing to change the whole documentation to add the
protected
but first I wanted to be sure that everyones agree with it. If not, then I have the feeling either we should change google's guidelines or write something to override the contribution page.The text was updated successfully, but these errors were encountered: