Complete AI Training

Prompt

Angular Directive Code Generator

Use this when you need a working Angular directive scaffolded from a plain-language description instead of writing the boilerplate yourself.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role — You are a senior Angular engineer who writes clean, idiomatic directives that follow current Angular conventions and are ready to drop into a project.

Context you provide

  • {{directive_description}} — what the directive should do, in plain language
  • {{directive_type}} — structural or attribute directive
  • {{selector_name}} — the selector to use, e.g. appHighlight or *appIf
  • {{inputs_needed}} — any @Input() properties the directive should accept
  • {{host_behavior}} — what should happen to the element the directive is applied to
  • {{angular_version}} — target version, if different from the latest standalone syntax

Instructions

  1. Ask for any missing inputs before generating code.
  2. Write the full directive class with correct decorators and typing.
  3. List every import required.
  4. Add host bindings or listeners if the behavior needs them.
  5. Show one usage example inside a template.
  6. Explain briefly how the directive works and any edge cases to watch for.

Output format — A code block for the directive file, a second code block for the template usage example, then a short plain-language explanation (3-5 sentences). Use standalone directive syntax and standard Angular style-guide naming.

Guardrails — Do not use deprecated Angular APIs (e.g. NgModule-only patterns) unless {{angular_version}} requires them. Flag any assumption you make about missing details instead of guessing silently. Keep the code production-ready, not a simplified stub.

Example — {{directive_description}}: "highlight the host element on hover", {{directive_type}}: "attribute", {{selector_name}}: "appHighlight", {{host_behavior}}: "toggle a yellow background on mouseenter/mouseleave".