angular-best-practices
БесплатноБез исполняемых скриптовНе проверенAngular 21 development with modern best practices including signals, standalone components, reactive patterns, and accessibility. Use when creating Angular…
от Boise-State-Development★ 22 звезды на GitHubОб этом скилле
Angular 21 Best Practices
TypeScript
- Use strict type checking
- Prefer type inference when type is obvious
- Avoid
any; useunknownwhen type is uncertain
Components
- Always use standalone components (do NOT set
standalone: true— it's the default in v20+) - Set
changeDetection: ChangeDetectionStrategy.OnPush - Use
input()andoutput()functions instead of decorators - Use
computed()for derived state - Keep components small and single-responsibility
- Prefer inline templates for small components
- Use Reactive forms over Template-driven
- Use
classbindings instead ofngClass - Use
stylebindings instead ofngStyle - For external templates/styles, use paths relative to the component TS file
- Do NOT use
@HostBinding/@HostListener— use thehostobject in the decorator instead
State Management with Signals
- Use signals for local component state
- Use
computed()for derived state - Keep state transformations pure and predictable
- Do NOT use
mutateon signals — useupdateorsetinstead
For complex derived state patterns, see references/signal-patterns.md.
Resources (Async Data)
Use resource() for async data fetching with signals:
const userResource = resource({
params: () => ({ id: userId() }),
loader: ({ params, abortSignal }) => fetch(`/api/users/${params.id}`, { signal: abortSignal }),
});
const userName = computed(() => userResource.hasValue() ? userResource.value().name : undefined);
Key resource patterns:
paramsreturnsundefined→ loader doesn't run, status becomes'idle'- Use
abortSignalto cancel in-flight requests - Check
hasValue()before accessingvalue()to handle loading/error states - Status values:
'idle','loading','reloading','resolved','error','local' reload()keeps the current value while it fetches ('reloading'). A newparamsvalue drops it and goes back to'loading'
Lists are cached in a root service, not on the page
A resource is destroyed with the injector that created it. A resource() field on a page component therefore fetches again, with a spinner, every time the user comes back. For a list the user returns to, the resource lives in a providedIn: 'root' service, loads lazily, and is refreshed by the service's own writes:
@Injectable({ providedIn: 'root' })
export class ThingsService {
private readonly http = inject(HttpClient);
private readonly wanted = signal(false);
/** Idle until a page opens it, so injecting the service elsewhere fetches nothing. */
readonly things = resource({
params: () => (this.wanted() ? true : undefined),
loader: () => firstValueFrom(this.http.get<Thing[]>('/api/things')),
});
/** The page calls this on entry: the first call loads, later ones refresh behind the shown copy. */
open(): void {
if (!this.wanted()) this.wanted.set(true);
else this.things.reload();
}
async remove(id: string): Promise<void> {
await firstValueFrom(this.http.delete(`/api/things/${id}`));
if (!this.wanted()) return;
if (this.things.hasValue()) this.things.set(this.things.value().filter((t) => t.id !== id));
this.things.reload();
}
}
// The page: show the loading state only when there is nothing to show yet.
// @if (!things.hasValue() && things.isLoading()) { Loading… }
Keep a component-level resource() for data that belongs to one view and should be read fresh each time, such as a record opened by id. The frontend CLAUDE.md ("Lists the user comes back to") has the full rule. WorkflowsApiService.workflows is the example in this codebase.
Templates
- Use native control flow:
@if,@for,@switch(NOT*ngIf,*ngFor,*ngSwitch) - Use async pipe for observables
- Keep templates simple — no complex logic
- Do NOT use arrow functions in templates (not supported)
- Do NOT assume globals like
new Date()are available
Services
- Single responsibility per service
- Use
providedIn: 'root'for singletons - Use
inject()function instead of constructor injection
@Injectable({ providedIn: 'root' })
export class UserService {
private readonly http = inject(HttpClient);
}
Routing
- Implement lazy loading for feature routes:
export const routes: Routes = [
{
path: 'admin',
loadComponent: () => import('./admin/admin.page').then(m => m.AdminPage),
},
];
File Naming
- Routable view components:
file-name.page.ts,file-name.page.html,file-name.page.css - Regular components:
file-name.component.ts - Services:
file-name.service.ts
Icons (ng-icon)
import { NgIcon, provideIcons } from '@ng-icons/core';
import { heroSparkles, heroTrash } from '@ng-icons/heroicons/outline';
@Component({
selector: 'app-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIcon],
providers: [provideIcons({ heroSparkles, heroTrash })],
Установить angular-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл angular-best-practices?
Angular 21 development with modern best practices including signals, standalone components, reactive patterns, and accessibility. Use when creating Angular components, services, templates, or performing any Angular frontend development work. Covers TypeScript strict typing, signal-based state management, reactive forms, lazy loading, ng-icon setup, and Tailwind styling.
Как установить скилл angular-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл angular-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic