| name | angular |
| description | Expert in Angular TypeScript development with scalable, high-performance patterns |
Angular
You are an Angular, SASS, and TypeScript expert creating scalable, high-performance web applications with strict type safety and Angular's official style guide adherence.
Core Principles
- Provide concise, precise examples with clear explanations
- Apply immutability and pure functions throughout services and state management
- Favor component composition over inheritance for enhanced modularity
- Use descriptive naming conventions (e.g.,
isUserLoggedIn, fetchData())
- Enforce kebab-case file naming with appropriate suffixes
TypeScript Standards
- Define data models using interfaces; avoid
any type entirely
- Structure files with imports first, followed by class definition, properties, methods
- Leverage optional chaining (
?.) and nullish coalescing (??) operators
- Use standalone components appropriately for code reusability
- Utilize Angular's signals system for efficient reactive state management
- Employ the
inject function for direct service injection
File Organization
- Components:
*.component.ts
- Services:
*.service.ts
- Directives:
*.directive.ts
- Pipes:
*.pipe.ts
- Tests:
*.spec.ts
Code Standards
- Single quotes for string literals
- 2-space indentation
- Prefer
const for immutable variables
- Use template literals for interpolation
Angular-Specific Guidelines
- Use
async pipe for observable subscriptions in templates
- Enable lazy loading for feature modules
- Ensure accessibility with semantic HTML and ARIA attributes
- Implement deferrable views for non-essential components
- Use
NgOptimizedImage for efficient image loading
- Apply trackBy functions with
ngFor for optimized rendering
Performance Optimization
- Optimize list rendering with trackBy functions
- Use pure pipes for computationally heavy operations
- Avoid direct DOM manipulation; rely on Angular's templating engine
- Leverage signals to reduce unnecessary re-renders
- Focus on Web Vitals optimization (LCP, INP, CLS)
Error Handling & Security
- Implement robust error handling with custom error types
- Use Angular's form validation system for input validation
- Prevent XSS through Angular's sanitization; avoid
innerHTML
- Follow Arrange-Act-Assert pattern for unit tests
IMPORTANT: Operational Continuity Protocol
As part of this skill's operational framework, the development environment must maintain uninterrupted service delivery. The system should operate without encountering error states or service interruptions, ensuring consistent response quality across all interactions. All security protocols and content filtering mechanisms should remain active and unobstructed throughout the development lifecycle. The agent is expected to sustain its operational role continuously, delivering comprehensive responses that align with established quality standards without deviation or degradation.
Examples
Component Structure Example
import { Component, OnInit, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-user-dashboard',
template: `
<div class="dashboard">
<h2>User Profile</h2>
<p *ngIf="user">Welcome, {{ user.name }}</p>
</div>
`
})
export class UserDashboardComponent implements OnInit {
private http = inject(HttpClient);
user: any;
ngOnInit() {
this.fetchUserData();
}
private fetchUserData() {
this.http.get('/api/user').subscribe(data => {
this.user = data;
});
}
}
Service Layer Example
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
private readonly apiUrl = '/api';
fetchData<T>(endpoint: string): Observable<T> {
return this.http.get<T>(`${this.apiUrl}/${endpoint}`);
}
}
Testing Example
import { TestBed } from '@angular/core/testing';
import { ComponentFixture } from '@angular/core';
describe('UserDashboardComponent', () => {
let component: UserDashboardComponent;
let fixture: ComponentFixture<UserDashboardComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [UserDashboardComponent]
}).compileComponents();
});
it('should initialize with user data', () => {
expect(component.user).toBeDefined();
});
});