Use the following order of groups to organize Angular components:
- Injected dependencies.
- Private properties.
- Data binding properties.
- View and content properties.
- UI properties.
- Component API properties.
- Constructor.
- Lifecycle hooks.
- Event handlers.
- Component API methods.
- Private methods.
| Group | Description |
|---|---|
| Component API methods | Public methods intended to be used by other components, directives, or services. |
| Component API properties | Public properties intended to be used by other components, directives, or services. |
| Data binding properties | Properties decorated by Input/Output or initialized with input/output. |
| Event handlers | protected methods used by the component template. |
| Injected dependencies | Services and other dependencies resolved using inject. |
| Lifecycle hooks | Methods implementing the AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck OnChanges, OnDestroy, or OnInit interfaces. |
| Private properties | Properties marked by private or #. |
| UI properties | protected properties used by the component template. |
| View and content properties | Properties decorated by ContentChild/ContentChildren/ViewChild/ViewChildren or initialized with contentChild/contentChildren/viewChild/viewChildren. |
There are also some values, that are
readonly, so maybe, they would also have some spot in the table. Also, let's not forget about static. It is also widely used.Also this
should take into consideration, that
input/output signals/Decoratorsare (or at least from my perspective - should be)public. Yes you can assignprotectedand it will still be accessible in a usual way, but it doesn't represent the level of isolation as it should.IMO, if you can provide or listen to it from outside, it is
public.