☰ Categories

Angular Directive Generator

an expert Angular developer. Generate a complete Angular directive based on the following description: Directive Description: ${description} Directive

CategoryDevelopment › Coding
TagsDraftingDeveloperCodeTemplate
Prompt
You are an expert Angular developer. Generate a complete Angular directive based on the following description:

Directive Description: ${description}
Directive Type: [structural | attribute]
Selector Name: [e.g. appHighlight, *appIf]
Inputs needed: [list any @Input() properties]
Target element behavior: ${what_should_happen_to_the_host_element}

Generate:
1. The full directive TypeScript class with proper decorators
2. Any required imports
3. Host bindings or listeners if needed
4. A usage example in a template
5. A brief explanation of how it works

Use Angular 17+ standalone directive syntax. Follow Angular style guide conventions.

What this prompt does

Useful for quickly drafting an Angular directive. It asks for the TypeScript class, imports, host bindings or listeners, a template usage example, and a brief explanation.

Model comparison

Claude is the best-balanced and most accessible; Gemini is thorough but verbose. ChatGPT is concise but weaker on background restoration and lifecycle cleanup.

ClaudeTop overall
43/ 50

+ Adds strong keyboard and screen-reader support.

- Forced positioning and the SSR claim are flawed.

ChatGPT
41/ 50

+ Presents the core solution clearly and concisely.

- It loses prior backgrounds and lacks destroy cleanup.

Gemini
41/ 50

+ Implements every requested feature clearly.

- Repeated clicks may copy the tooltip text too.

CriterionChatGPTClaudeGeminiLeader
Instruction following91010Tie
Accuracy677Tie
Specificity999Tie
Structure899Tie
Right length986ChatGPT +13%

Scored 1–10 by gpt-5.6-sol with model names hidden (2026-09-24). This is an AI review, not a measurement.

Read full answers

We gave three models the same input and copied their answers unedited. Each ran in its CLI (an agent harness), and answers in the ChatGPT or Claude apps or on the web may differ. Outputs are in Korean.

Input used
[Pasted material]
Directive Description: 요소에 마우스를 올리면 배경색이 부드럽게 하이라이트되고, 클릭하면 해당 요소의 내용을 클립보드에 복사하는 디렉티브
Directive Type: attribute
Selector Name: appCopyHighlight
Inputs needed: highlightColor (string, 기본값 '#fef08a'), copyText (복사할 텍스트, 없으면 innerText 사용)
Target element behavior: hover 시 배경색 트랜지션 적용, click 시 텍스트 복사 후 잠깐 '복사됨!' 툴팁 표시
gpt-5.6-luna (codex CLI · 에이전트 하네스) · Run on 2026-09-24
import {
  Directive,
  ElementRef,
  HostListener,
  Input,
  Renderer2,
  inject,
} from '@angular/core';

@Directive({
  selector: '[appCopyHighlight]',
  standalone: true,
})
export class CopyHighlightDirective {
  @Input() highlightColor = '#fef08a';
  @Input() copyText?: string;

  private readonly elementRef = inject(ElementRef<HTMLElement>);
  private readonly renderer = inject(Renderer2);

  private tooltip?: HTMLElement;
  private tooltipTimer?: ReturnType<typeof setTimeout>;

  constructor() {
    const element = this.elementRef.nativeElement;

    this.renderer.setStyle(element, 'transition', 'background-color 180ms ease');

    if (getComputedStyle(element).position === 'static') {
      this.renderer.setStyle(element, 'position', 'relative');
    }

    this.renderer.setStyle(element, 'cursor', 'pointer');
  }

  @HostListener('mouseenter')
  onMouseEnter(): void {
    this.renderer.setStyle(
      this.elementRef.nativeElement,
      'background-color',
      this.highlightColor,
    );
  }

  @HostListener('mouseleave')
  onMouseLeave(): void {
    this.renderer.removeStyle(
      this.elementRef.nativeElement,
      'background-color',
    );
  }

  @HostListener('click')
  async onClick(): Promise<void> {
    const text = this.copyText?.trim() || this.elementRef.nativeElement.innerText;

    if (!text.trim()) {
      return;
    }

    try {
      await navigator.clipboard.writeText(text);
      this.showTooltip('복사됨!');
    } catch {
      this.showTooltip('복사 실패');
    }
  }

  private showTooltip(message: string): void {
    this.removeTooltip();

    const tooltip = this.renderer.createElement('span') as HTMLElement;
    this.tooltip = tooltip;

    this.renderer.setProperty(tooltip, 'textContent', message);
    this.renderer.setAttribute(tooltip, 'role', 'status');
    this.renderer.setAttribute(tooltip, 'aria-live', 'polite');

    this.renderer.setStyle(tooltip, 'position', 'absolute');
    this.renderer.setStyle(tooltip, 'top', '100%');
    this.renderer.setStyle(tooltip, 'left', '50%');
    this.renderer.setStyle(tooltip, 'transform', 'translateX(-50%)');
    this.renderer.setStyle(tooltip, 'margin-top', '6px');
    this.renderer.setStyle(tooltip, 'padding', '4px 8px');
    this.renderer.setStyle(tooltip, 'border-radius', '4px');
    this.renderer.setStyle(tooltip, 'background-color', '#1f2937');
    this.renderer.setStyle(tooltip, 'color', '#fff');
    this.renderer.setStyle(tooltip, 'font-size', '12px');
    this.renderer.setStyle(tooltip, 'white-space', 'nowrap');
    this.renderer.setStyle(tooltip, 'z-index', '1000');
    this.renderer.setStyle(tooltip, 'pointer-events', 'none');

    this.renderer.appendChild(this.elementRef.nativeElement, tooltip);

    this.tooltipTimer = setTimeout(() => {
      this.removeTooltip();
    }, 1500);
  }

  private removeTooltip(): void {
    if (this.tooltip) {
      this.renderer.removeChild(
        this.elementRef.nativeElement,
        this.tooltip,
      );
      this.tooltip = undefined;
    }

    if (this.tooltipTimer) {
      clearTimeout(this.tooltipTimer);
      this.tooltipTimer = undefined;
    }
  }
}

사용 예시:

import { Component } from '@angular/core';
import { CopyHighlightDirective } from './copy-highlight.directive';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [CopyHighlightDirective],
  template: `
    <p
      appCopyHighlight
      highlightColor="#bfdbfe"
    >
      이 문장을 클릭하면 복사됩니다.
    </p>

    <button
      appCopyHighlight
      [copyText]="'버튼 클릭으로 복사되는 별도 텍스트'"
      highlightColor="#bbf7d0"
    >
      텍스트 복사
    </button>
  `,
})
export class ExampleComponent {}

마우스를 올리면 background-color가 부드럽게 변경되고, 클릭하면 copyText 값을 클립보드에 복사합니다. copyText가 없으면 호스트 요소의 innerText를 사용하며, 복사 후 1.5초 동안 복사됨! 툴팁을 표시합니다.

More in this category

12-Month AI and Computer Vision Roadmap for Defense Applications
2046 Puzzle Game Challenge
21st.dev component prompt
3D FACTORY
3D FPS Game