Community编程与开发github.com

analogjs/angular-directives

在 Angular v20+ 中创建自定义指令,用于 DOM 操作和行为扩展。适用于属性指令(修改元素行为/外观)、结构指令(门户/覆盖层)和宿主指令(组合)。触发场景包括创建可复用的 DOM 行为、扩展元素功能或在组件间组合行为。注意:对于控制流,请使用原生 @if/@for/@switch,不要使用自定义结构指令。

angular-directives 是什么?

该技能专为 Angular v20+ 开发人员设计,用于创建自定义指令,以实现高级 DOM 操作和行为扩展。它支持三种指令类型:属性指令(修改元素行为或外观)、结构指令(用于门户和覆盖层等动态视图)以及宿主指令(实现跨组件的行为组合)。核心价值在于提供可复用的 DOM 行为模式,避免重复代码,同时保持与 Angular 最新版本的兼容性。该技能明确建议使用 Angular 原生的 @if/@for/@switch 进行控制流管理,而非自定义结构指令,以确保最佳性能和最佳实践。支持的平台包括 Angular CLI 项目、Nx 单体仓库以及 Analog 等基于 Angular 的框架。工作原理基于 Angular 指令的装饰器模式,通过 @Directive 装饰器和对应的生命周期钩子(如 ngOnInit, ngOnChanges)来实现行为绑定和视图操作。

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

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

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

文档

angular-directives 是做什么的?

在 Angular v20+ 中创建自定义指令,用于 DOM 操作和行为扩展。适用于属性指令(修改元素行为/外观)、结构指令(门户/覆盖层)和宿主指令(组合)。触发场景包括创建可复用的 DOM 行为、扩展元素功能或在组件间组合行为。注意:对于控制流,请使用原生 @if/@for/@switch,不要使用自定义结构指令。

Individual skills in this repo

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

analogjs/angular-component

Create modern Angular standalone components following v20+ best practices. Use for building UI components with signal-based inputs/outputs, OnPush change detection, host bindings, content projection, and lifecycle hooks. Triggers on component creation, refactoring class-based inputs to signals, adding host bindings, or implementing accessible interactive components.

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-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.

相关技能