This is a comprehensive reference for Angular 21 directive patterns, covering attribute directives, structural directives, and the newer directive composition API. You'll want this when building reusable DOM behaviors or working with Angular's hostDirectives feature. The examples are practical and show both traditional decorators and the newer signal-based inputs. The code snippets lean heavily on best practices like using Renderer2 for DOM manipulation and keeping directives focused on single responsibilities. It's current for Angular 21 and includes the modern control flow syntax, though if you're still on older versions you'll need to mentally translate some of the examples back to NgModule patterns.

skills.sh installs
176
GitHub stars
7
last updated
Aug 21, 2026

Install

$ npx -y skills add oguzhan18/angular-ecosystem-skills --skill angular-directives --agent claude-code

Installs into .claude/skills of the current project.

Files

Angular Directives

Version: Angular 21 (2025) Tags: Directives, Components, DOM, Custom Directives

References: Directives Guide • Attribute Directives • Structural Directives

API Changes

This section documents recent version-specific API changes.

  • NEW: Directive composition API — Use hostDirectives to compose directives source

  • NEW: Signal inputs in directives — Use input() for reactive directive properties

  • NEW: Standalone directives — All directives can be standalone

  • NEW: Control flow syntax — @if, @for, @switch replace *ngIf, *ngFor

Best Practices

  • Create attribute directives for reusable behavior
import { Directive, ElementRef, Renderer2, Input } from '@angular/core';

@Directive({
  selector: '[appHighlight]'
})
export class HighlightDirective {
  @Input() set appHighlight(color: string) {
    this.renderer.setStyle(this.el.nativeElement, 'background-color', color || 'yellow');
  }

Sponsors

Details

Repository
github.com/oguzhan18/angular-ecosystem-skills
Category
Frontend Development
First seen
Jun 3, 2026

More from oguzhan18/angular-ecosystem-skills

All 45
1sickn33 avatarreact-flow-architectsickn33/antigravity-awesome-skillsreact flow architect176skills.sh installs
2oguzhan18 avatarangular-routeroguzhan18/angular-ecosystem-skillsALWAYS use when working with Angular Router, routing configuration, guards, resolvers, lazy loading, or navigation in Angular applications.172skills.sh installs
3tuziapi avatartuzi-markdown-to-htmltuziapi/tuzi-skills将 Markdown 转换为带样式的 HTML,支持微信公众号兼容主题。支持代码高亮、数学公式、PlantUML、脚注、提示框和信息图。当用户要求 "markdown to html"、"md转html"、"转换为html" 时使用。164skills.sh installs
4nexu-io avatarhtml-ppt-taste-editorialnexu-io/open-design16:9 HTML deck in editorial-minimalist taste. Warm cream slides, serif display + grotesque body, hairline rules, monospace meta, generous macro-whitespace, one 160skills.sh installs
5bobmatnyc avatarreact-state-machinesbobmatnyc/claude-mpm-skillsBuilding reusable React state machine skills with XState v5 and the actor model158skills.sh installs
6kingdee avatarkwc-react-developmentkingdee/kwc-skills【由 kwc-project-scaffold 调度】仅负责 React 组件代码编写,不直接承接用户需求,不创建文件。所有 KWC 需求和文件创建必须先经 kwc-project-scaffold。158skills.sh installs