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
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
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
- Ask for any missing inputs before generating code.
- Write the full directive class with correct decorators and typing.
- List every import required.
- Add host bindings or listeners if the behavior needs them.
- Show one usage example inside a template.
- 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".