1.6 KiB
1.6 KiB
name, description
| name | description |
|---|---|
| angular-access-modifiers-francisco-rangel | Enforces explicit TypeScript access modifiers (public/protected/private) on every class member of an Angular component, directive, or pipe based on usage. |
Angular Access Modifiers
Every field, getter/setter, and method on an Angular class must have an explicit TypeScript access modifier. Never leave members implicit.
Visibility Rules
| Used in HTML template? | Used only inside TS class? | External access (Parent, Test, Service)? | Access Modifier |
|---|---|---|---|
| Yes | — | — | protected |
| No | Yes | No | private |
| No | — | Yes | public |
Instructions
protected: Use for all properties, signals, getters/setters, and methods accessed directly inside the template (.htmlor inlinetemplate).private: Use for internal logic, helper methods, state variables, or subscriptions that are never accessed outside this single file.public: Use ONLY for@Input(),@Output(), component inputs/outputs created via functions (input(),output()), public API methods called by parents/tests, or Angular lifecycle hooks (ngOnInit,ngOnDestroy, etc.).- Never leave any member without an explicit modifier.
Examples
❌ Incorrect (Implicit or misscoped)
@Component({ ... })
export class UserProfileComponent {
userName = signal('John'); // Implicit public (avoid)
ngOnInit() { // Implicit public
this.fetchData();
}
fetchData() { // Implicit public
// ...
}
}