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 . |
Are there any tools that help checking the order is consistent?