angular-directives_skill

This skill helps Angular developers create reusable directives for DOM manipulation, behavior extension, and composition across components.

101

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill analogjs/angular-skills --skill angular-directives

  • SKILL.md10.8 KB

Overview

This skill teaches how to create custom directives in Angular v20+ for reusable DOM manipulation and composable behaviors. It covers attribute directives, structural directives for portals and lazy rendering, and host directives for composing behaviors on components. The guidance focuses on practical patterns using the modern inject/input/output/effect APIs and recommends native control-flow directives for conditionals and loops.

How this skill works

The skill inspects common UI needs and maps them to three directive types: attribute directives to change appearance or attach behavior, structural directives to insert or move templates in the DOM, and host directives to compose reusable behaviors onto components. Examples demonstrate using inputs, outputs, host bindings, document-level event handlers, and the new hostDirectives composition API. Each pattern shows lifecycle handling, DOM placement, and defensive checks to keep directives predictable and performant.

When to use it

  • Add reusable element behavior like tooltips, keyboard shortcuts, or click-outside detection.
  • Modify classes, styles, or attributes declaratively across many elements (buttons, form controls).
  • Render content outside the component tree (modals, overlays, portals) or defer heavy content until needed.
  • Compose shared behaviors (focus, disable, ripple) across multiple components without code duplication.
  • Expose host directive outputs and inputs on wrapper components for seamless event forwarding.

Best practices

  • Prefer host property on @Directive for bindings and listeners instead of @HostBinding/@HostListener.
  • Use native @if/@for/@switch for control flow; reserve structural directives for portals, outlets, or one-time lazy render.
  • Keep directive inputs small and use booleanAttribute transform for flag-style inputs.
  • Attach document-level listeners carefully and clean up on destroy to avoid memory leaks.
  • Compose behavior with hostDirectives to share logic and forward inputs/outputs instead of inheritance.

Example use cases

  • Attribute directive to highlight elements or toggle button variants and disabled state.
  • Tooltip directive that appends an accessible tooltip element to document.body and positions it.
  • Portal directive to render modals or menus at body level while maintaining template context.
  • LazyRender directive to postpone heavy component creation until the user activates a tab.
  • Host directives to add focus, hover, disable, ripple, or elevation behaviors to custom components.

FAQ

Use native @if/@for/@switch for conditionals and lists. Create structural directives only when you need to move templates between DOM locations, defer one-time rendering, or provide a custom template outlet.

How do I forward events and inputs from host directives?

Use hostDirectives to attach directives to a component and declare inputs/outputs mapping in the hostDirectives entry so the component surface exposes them directly.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational