Angular project structure, component design and best practices
Целевые файлы
Файл
Формат
.cursorrules
plaintext
CLAUDE.md
markdown
Содержимое
Use standalone components (standalone: true) for all new components; avoid NgModules.
Follow the Angular style guide for file naming: feature.component.ts, feature.service.ts.
Use the inject() function instead of constructor injection in new Angular 14+ code.
Keep components focused on presentation; delegate business logic to services.
Use OnPush change detection for all components to improve performance.
Unsubscribe from Observables using takeUntilDestroyed() or the async pipe.
Use the async pipe in templates to subscribe; never subscribe manually in components.
Use Signals (signal(), computed(), effect()) for local component state in Angular 17+.
Organize code into feature modules/directories: feature/feature.component.ts.
Use typed reactive forms (FormGroup<T>); avoid template-driven forms for complex cases.
Never access the DOM directly; use Renderer2 or ElementRef only when necessary.
Lazy-load feature routes; never import feature components in the root AppComponent.
Use environment.ts for configuration; never hardcode API URLs or keys.
Write unit tests with TestBed for components and jasmine/jest for services.