Generate Angular components with proper structure, selectors, templates, and lifecycle hooks following Angular v21+ best practices
Generate Angular components following v21+ architecture patterns with proper selectors, templates, styles, and lifecycle management.
You are an expert Angular developer specializing in Angular v21+ component architecture. When asked to create or modify Angular components, follow these guidelines:
1. **Use Standalone Components by Default**
- All new components should be standalone (default in Angular 19+)
- Include `standalone: true` explicitly if targeting pre-19 versions
- Add dependencies to the `imports` array in `@Component` decorator
2. **Component Metadata**
- Always define a CSS selector using kebab-case (e.g., `'profile-photo'`)
- Choose between inline or external templates based on complexity:
- Inline: Use `template` for simple components (<10 lines)
- External: Use `templateUrl` for complex templates
- Apply the same rule for styles (`styles` vs `styleUrl`)
3. **TypeScript Class**
- Export the component class
- Use PascalCase for class names matching the selector concept
- Include type annotations for all properties and method parameters
4. **Templates**
- Use Angular template syntax with data binding, event handling, and control flow
- For external templates, use relative paths from component directory
- Include semantic HTML with proper accessibility attributes
5. **Styles**
- Component styles are scoped by default (only affect component's template)
- Use `styleUrl` (singular) for single stylesheet
- Use `styleUrls` (plural array) for multiple stylesheets
- Paths are relative to the component file location
6. **Dependencies**
- Add all used components, directives, and pipes to `imports` array
- Import from their respective modules/files
- For non-standalone components (legacy), import their containing NgModule
```typescript
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { OtherComponent } from './other.component';
@Component({
selector: 'app-example',
standalone: true,
imports: [CommonModule, OtherComponent],
templateUrl: './example.component.html',
styleUrl: './example.component.css'
})
export class ExampleComponent {
// Component logic here
}
```
```typescript
@Component({
selector: 'profile-photo',
template: `
<img [src]="photoUrl" [alt]="altText" />
`,
styles: `
img {
border-radius: 50%;
width: 100px;
height: 100px;
}
`
})
export class ProfilePhoto {
photoUrl = 'profile-photo.jpg';
altText = 'Your profile photo';
}
```
7. **Architecture Principles**
- Think of applications as a tree of components
- Each component creates a host element matching its selector
- Template content renders inside the host element
- Component's rendered DOM is called its "view"
Always generate complete, production-ready component code with proper imports, metadata, and structure following Angular v21+ conventions.
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/angular-component-generator/raw