Token导航 LogoToken导航TokenDH.com
开发规范需要联网github未标认证来源可访问许可证需确认审计通过

angular-best-practicesAngular 最佳实践

Agent Skill

angular-best-practices 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

12,129

周安装

521

GitHub Stars

31

下载量

4,251
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:angular-best-practices(Angular 最佳实践)
来源仓库:https://github.com/alfredoperez/angular-best-practices
仓库路径:skills/angular-best-practices
安装命令:
npx skills add https://github.com/alfredoperez/angular-best-practices --skill angular-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/alfredoperez/angular-best-practices --skill angular-best-practices

简介

使用信号和现代 API 的高性能、可维护的 Angular 17+ 应用程序的综合风格指南。

  • 涵盖 TypeScript 严格性、带有 OnPush 的独立组件
  • 检测,使用 input() 进行基于信号的反应,输出(),和计算(),和控制流语法(@if,@for,@开关)
  • 包括 RxJS 模式、性能优化(路由解析器、延迟加载、@defer)、使用组件线束进行测试以及架构指南
  • 可选的库特定附加组件可用于 NgRx、SignalStore、TanStack Query、Material、PrimeNG、Spartan UI 和 Transloco
  • 不适用于 AngularJS、React、Vue 或非 Angular TypeScript 项目

SKILL.md

Modern Angular Best Practices

A comprehensive set of 112 rules covering TypeScript strictness, signal-based reactivity, component architecture, template optimization, RxJS patterns, SSR hydration, bundle optimization, accessibility, routing, forms, testing, and styling — so every component, service, template, and route you build is fast, accessible, tested, and maintainable.

Below are the key patterns organized by what you're working on. For edge cases or when you need specific code examples beyond what's listed here, consult the AGENTS.md reference file in this skill directory.

Components & Signals

Components are the building blocks. Modern Angular uses signals for reactivity, which changes how you write everything from state to templates.

  • Use standalone components with ChangeDetectionStrategy.OnPush
  • Use input(), output(), model() signal functions instead of decorators
  • Use inject() instead of constructor injection
  • Use signal() for local state, computed() for derived state
  • Use linkedSignal() when state should reset when a source changes
  • Use resource() / httpResource() for async data with built-in loading states
  • Use effect() only for side effects — never for state synchronization
  • Use toSignal() to bridge RxJS observables into signal-based templates
  • Use viewChild() / contentChild() signal queries instead of decorators
  • Use the host property instead of @HostBinding / @HostListener

Templates & Styles

Templates and styles work together — accessibility, layout, and performance cross both concerns.

  • Use @if, @for, @switch control flow instead of structural directives
  • Use @defer for heavy below-fold content
  • Always provide track with @for loops
  • Use NgOptimizedImage with priority for above-fold images
  • Use pure pipes instead of method calls in templates
  • Use CdkVirtualScrollViewport for large lists
  • Use [class.active] bindings instead of [ngClass]
  • Define theme values as CSS custom properties
  • Use prefers-reduced-motion to respect motion preferences

Services & RxJS

Services handle data flow, dependency injection, and RxJS patterns. HTTP, caching, and observable lifecycle are interconnected concerns.

  • Unsubscribe via takeUntilDestroyed() or async pipe
  • Place catchError inside switchMap to keep the outer stream alive
  • Use switchMap for latest-only, exhaustMap for ignore-while-busy
  • Use shareReplay({bufferSize: 1, refCount: true}) for shared streams
  • Use inject() with InjectionToken for configuration
  • Use HTTP interceptors for cross-cutting concerns (auth, retry, logging)
  • Map DTOs at the API boundary — don't leak backend shapes into components

Performance & SSR

Performance rules span components, templates, and infrastructure. SSR affects routing, data fetching, and hydration strategy.

  • Preload critical data with route resolvers to eliminate waterfalls
  • Lazy-load routes and @defer heavy views
  • Tree-shake imports via standalone component imports, not modules
  • Batch DOM reads/writes to avoid layout thrashing
  • Use Map/Set over plain objects/arrays for frequent lookups
  • Use incremental hydration (@defer (hydrate on...)) for large pages
  • Use provideClientHydration(withEventReplay()) for SSR
  • Set render modes per-route: SSR for SEO, CSR for dashboards

Testing

Testing patterns apply to components, services, and templates together — isolation is important but integration context matters.

  • Use component harnesses over direct DOM queries
  • Create test object factories for consistent test data
  • Test signal state changes and template output, not implementation
  • Mock services with jasmine.createSpyObj or jest.fn()
  • Test accessibility with axe-core or jest-axe

Architecture & Routing

Architecture decisions affect every file type — routing, module boundaries, and dependency injection are structural.

  • One feature per lazy-loaded route
  • Use guards for auth, resolvers for data, canDeactivate for unsaved changes
  • Use preload strategies (QuickLinkStrategy) for likely-next routes
  • Bind route params via input() with withComponentInputBinding()
  • Avoid barrel file re-exports — import directly from source
  • Use environment-based configuration — no hardcoded URLs or API keys

TypeScript Foundations

These apply everywhere — components, services, tests, all .ts files.

  • Use strict type checking with strict: true in tsconfig
  • Avoid any; use unknown when type is uncertain, generics to narrow
  • Use import type for type-only imports
  • Add explicit return types to exported functions
  • Prefer readonly for data that should not be mutated
  • Use discriminated unions for state variants
  • Use the Result pattern for operations that can fail

Accessibility

Accessibility spans templates, styles, and components — it's not just an HTML concern.

  • Use semantic HTML elements first (<nav>, <main>, <button>)
  • Use ARIA roles and aria-live regions for dynamic content
  • Ensure all interactive elements are keyboard-accessible
  • Use cdkTrapFocus for dialogs and overlays
  • Test with screen readers and axe-core

Quick Reference

PatternUseAvoid
Signal inputsinput<T>()@Input()
Signal outputsoutput<T>()@Output()
Two-way bindingmodel<T>()input + output pair
Dependency injectioninject()Constructor injection
Control flow@if, @for, @switch*ngIf, *ngFor
Class binding[class.active][ngClass]
Change detectionOnPushDefault
Derived statecomputed()Getters
View queriesviewChild()@ViewChild()

Key Code Patterns

Signal inputs and outputs (replaces decorators):

name = input<string>();           // @Input() replacement
save = output<Data>();            // @Output() replacement
value = model<string>();          // two-way binding

Control flow (replaces structural directives):

@if (user()) { <profile [user]="user()" /> }
@for (item of items(); track item.id) { <card [item]="item" /> }
@defer (on viewport) { <heavy-chart /> }

httpResource and resource (signal-based async):

users = httpResource<User[]>(() => `/api/users?role=${this.role()}`);
data = resource({ request: () => this.id(), loader: ({request}) => fetch(request) });

Optional Library Skills

Install library-specific rules alongside this core skill:

Links

License

MIT

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

38.01%
按下载量换算1,616

Claude

31.59%
按下载量换算1,343

Cursor

16.18%
按下载量换算688

Gemini CLI

9.65%
按下载量换算410

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills