angular-directives

Create custom attribute, structural, and host directives in Angular v20+ for DOM manipulation.

Updated Aug 10, 2025
One-click install
npx skills add https://github.com/afonsoft/ai-studio-workspace --skill angular-directives-afonsoft
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: angular-directives
Source: https://github.com/afonsoft/ai-studio-workspace/tree/main/agents/skills/angular-directives
Command: npx skills add https://github.com/afonsoft/ai-studio-workspace --skill angular-directives-afonsoft

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building reusable DOM behaviors in Angular often leads to duplicated logic scattered across components. This Skill provides patterns for encapsulating DOM manipulation, event handling, and behavior composition into reusable custom directives. ## Core Features & Use Cases - Attribute Directives: Modify element appearance and behavior with signal-based inputs, host bindings, and event handling (tooltips, click-outside, keyboard shortcuts). - Structural Directives: Build portals, lazy rendering, and template outlets for DOM insertion beyond native control flow. - Host Directives & Composition: Compose behaviors like focusable, disableable, and hoverable onto components using the hostDirectives API. - Use Case: You need a reusable tooltip, infinite scroll, or permission-based visibility across your Angular app. Use this Skill to generate a directive with proper signal inputs, outputs, and cleanup logic instead of copying component code. ## Quick Start Create an Angular attribute directive that highlights an element with a configurable color input using signals and the host property.

Frequently Asked Questions about angular-directives

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a custom attribute directive in Angular?▼

Define a class with the @Directive decorator and a bracketed selector like '[appHighlight]'. Use signal-based input() with an alias matching the selector, inject ElementRef, and apply DOM changes inside an effect() or via the host property.

How to use host directives in Angular for behavior composition?▼

Add the hostDirectives array to a component's @Component metadata, listing directive classes. You can expose their inputs and outputs using the inputs and outputs options, letting consumers configure composed behaviors like disableable or hoverable directly on the component.

Should I use @HostBinding or the host property in Angular directives?▼

Prefer the host property in the @Directive decorator over @HostBinding and @HostListener decorators. The host property centralizes event listeners, class bindings, and attribute bindings in one declarative object, which is the recommended modern Angular pattern.

When should I not create a custom structural directive in Angular?▼

Do not create structural directives for conditionals or loops; use native @if, @for, and @switch control flow instead. Reserve structural directives for DOM manipulation beyond control flow, such as portals, overlays, lazy rendering, or permission-based visibility.

How do I implement infinite scroll with an Angular directive?▼

Use an IntersectionObserver inside a directive created in afterNextRender, observing the host element. Emit an output when the sentinel element intersects the viewport, and disconnect the observer in ngOnDestroy or when a disabled input is true.