Community写作与编辑github.com

analogjs/angular-component

创建遵循Angular v20+最佳实践的现代独立组件。用于构建基于信号的输入/输出、OnPush变更检测、宿主绑定、内容投射和生命周期钩子的UI组件。触发场景包括创建新组件、重构基于类的输入为信号、添加宿主绑定或实现可访问的交互式组件。

angular-component 是什么?

该技能帮助开发者在Angular v20+中创建现代独立组件,遵循最新的最佳实践。它专注于使用signal-based输入/输出、OnPush变更检测策略、宿主绑定、内容投射和生命周期钩子。技能适用于组件创建、将基于class的输入重构为信号、添加宿主绑定以及实现可访问的交互式组件。通过自动化这些模式,开发者可以减少样板代码,提高组件一致性,并确保符合当前Angular的推荐实践。该技能适用于Claude Code、Cursor和Codex等AI代理平台。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/analogjs/angular-skills/tree/main/skills/angular-component

Installed? Explore more 写作与编辑 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

angular-component 是做什么的?

创建遵循Angular v20+最佳实践的现代独立组件。用于构建基于信号的输入/输出、OnPush变更检测、宿主绑定、内容投射和生命周期钩子的UI组件。触发场景包括创建新组件、重构基于类的输入为信号、添加宿主绑定或实现可访问的交互式组件。

能力

  • 使用 signal-based inputs/outputs 创建独立组件
  • 应用 OnPush 变更检测策略
  • 添加 宿主绑定 来样式化类、属性和事件
  • 使用 <ng-content> 实现 内容投射
  • 实现必要的 生命周期钩子(ngOnInit、ngOnDestroy 等)
  • 将基于 @Input() / @Output() 装饰器的类输入重构为 信号
  • 确保 可访问性(ARIA属性、键盘导航、焦点管理)

使用方法

示例:创建一个带有信号输入和输出($)的新可访问按钮组件:

import { Component, input, output, signal } from '@angular/core';

@Component({
  selector: 'app-accessible-button',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <button
      [disabled]="disabled()"
      (click)="onClick.emit()"
      (keydown.enter)="onClick.emit()"
      (keydown.space)="onClick.emit(); $event.preventDefault()"
      [attr.aria-label]="ariaLabel()"
      class="btn"
    >
      <ng-content></ng-content>
    </button>
  `,
  styles: [
    `
      .btn { /* 内联样式 */ }
    `
  ],
  host: {
    '[class.disabled]': 'disabled()'
  }
})
export class AccessibleButtonComponent {
  readonly label = input<string>('按钮');
  readonly disabled = input<boolean>(false);
  readonly ariaLabel = input<string>('');
  readonly onClick = output<void>();
}

提示与最佳实践

  • 对新组件始终使用 standalone: true
  • 使用 input() 和 output() 函数替换旧的装饰器
  • 在 host 属性中进行宿主绑定(而非在元数据中使用对象字面量)
  • 对于交互式组件,添加键盘支持和ARIA属性以确保无障碍访问
  • 将变更检测设置为 OnPush 以提升性能

适用平台

  • Claude Code
  • Cursor
  • Codex
  • 其他兼容的AI代理

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

analogjs/angular-di

Implement dependency injection in Angular v20+ using inject(), injection tokens, and provider configuration. Use for service architecture, providing dependencies at different levels, creating injectable tokens, and managing singleton vs scoped services. Triggers on service creation, configuring providers, using injection tokens, or understanding DI hierarchy.

analogjs/angular-directives

Create custom directives in Angular v20+ for DOM manipulation and behavior extension. Use for attribute directives that modify element behavior/appearance, structural directives for portals/overlays, and host directives for composition. Triggers on creating reusable DOM behaviors, extending element functionality, or composing behaviors across components. Note - use native @if/@for/@switch for control flow, not custom structural directives.

analogjs/angular-forms

Build signal-based forms in Angular v21+ using the new Signal Forms API. Use for form creation with automatic two-way binding, schema-based validation, field state management, and dynamic forms. Triggers on form implementation, adding validation, creating multi-step forms, or building forms with conditional fields. Signal Forms are experimental but recommended for new Angular projects. Don't use for template-driven forms without signals or third-party form libraries like Formly or ngx-formly.

analogjs/angular-http

Implement HTTP data fetching in Angular v20+ using resource(), httpResource(), and HttpClient. Use for API calls, data loading with signals, request/response handling, and interceptors. Triggers on data fetching, API integration, loading states, error handling, or converting Observable-based HTTP to signal-based patterns.

analogjs/angular-routing

Implement routing in Angular v20+ applications with lazy loading, functional guards, resolvers, and route parameters. Use for navigation setup, protected routes, route-based data loading, and nested routing. Triggers on route configuration, adding authentication guards, implementing lazy loading, or reading route parameters with signals.

analogjs/angular-signals

Implement signal-based reactive state management in Angular v20+. Use for creating reactive state with signal(), derived state with computed(), dependent state with linkedSignal(), and side effects with effect(). Triggers on state management questions, converting from BehaviorSubject/Observable patterns to signals, or implementing reactive data flows.

analogjs/angular-ssr

Implement server-side rendering and hydration in Angular v20+ using @angular/ssr. Use for SSR setup, hydration strategies, prerendering static pages, and handling browser-only APIs. Triggers on SSR configuration, fixing hydration mismatches, prerendering routes, or making code SSR-compatible.

analogjs/angular-testing

Write unit and integration tests for Angular v20+ applications using Vitest or Jasmine with TestBed and modern testing patterns. Use for testing components with signals, OnPush change detection, services with inject(), and HTTP interactions. Triggers on test creation, testing signal-based components, mocking dependencies, or setting up test infrastructure. Don't use for E2E testing with Cypress or Playwright, or for testing non-Angular JavaScript/TypeScript code.

analogjs/angular-tooling

Use Angular CLI and development tools effectively in Angular v20+ projects. Use for project setup, code generation, building, testing, and configuration. Triggers on creating new projects, generating components/services/modules, configuring builds, running tests, or optimizing production builds. Don't use for Nx workspace commands, custom Webpack configurations, or non-Angular CLI build systems like Vite standalone or esbuild direct usage.

相关技能