angular-core-implementation
Generate Angular components, services, modules, and directives. Implement dependency injection, lifecycle hooks, data binding, and build production-ready Angular architectures.
What this skill does
# Angular Core Implementation Skill
## Quick Start
### Component Basics
```typescript
import { Component, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-user-card',
template: `
<div class="card">
<h2>{{ user.name }}</h2>
<p>{{ user.email }}</p>
<button (click)="onDelete()">Delete</button>
</div>
`,
styles: [`
.card { border: 1px solid #ddd; padding: 16px; }
`]
})
export class UserCardComponent {
@Input() user!: User;
@Output() deleted = new EventEmitter<void>();
onDelete() {
this.deleted.emit();
}
}
```
### Service Creation
```typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root' // Singleton service
})
export class UserService {
private apiUrl = '/api/users';
constructor(private http: HttpClient) {}
getUsers(): Observable<User[]> {
return this.http.get<User[]>(this.apiUrl);
}
getUser(id: number): Observable<User> {
return this.http.get<User>(`${this.apiUrl}/${id}`);
}
createUser(user: User): Observable<User> {
return this.http.post<User>(this.apiUrl, user);
}
}
```
### Dependency Injection
```typescript
@Injectable()
export class NotificationService {
constructor(
private logger: LoggerService,
private config: ConfigService
) {}
notify(message: string) {
this.logger.log(message);
}
}
```
## Core Concepts
### Lifecycle Hooks
```typescript
export class UserListComponent implements
OnInit,
OnChanges,
OnDestroy
{
@Input() users: User[] = [];
ngOnInit() {
// Initialize component, fetch data
this.loadUsers();
}
ngOnChanges(changes: SimpleChanges) {
// Respond to input changes
if (changes['users']) {
this.onUsersChanged();
}
}
ngOnDestroy() {
// Cleanup subscriptions, remove listeners
this.subscription?.unsubscribe();
}
private loadUsers() { /* ... */ }
private onUsersChanged() { /* ... */ }
}
```
**Lifecycle Order:**
1. `ngOnChanges` - When input properties change
2. `ngOnInit` - After first ngOnChanges
3. `ngDoCheck` - Every change detection cycle
4. `ngAfterContentInit` - After content is initialized
5. `ngAfterContentChecked` - After content is checked
6. `ngAfterViewInit` - After view is initialized
7. `ngAfterViewChecked` - After view is checked
8. `ngOnDestroy` - When component is destroyed
### Modules
```typescript
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
UserListComponent,
UserDetailComponent,
UserFormComponent
],
imports: [
CommonModule,
FormsModule
],
exports: [
UserListComponent,
UserDetailComponent
]
})
export class UserModule { }
```
### Lazy Loading
```typescript
const routes: Routes = [
{ path: 'users', loadChildren: () =>
import('./users/users.module').then(m => m.UsersModule)
}
];
```
## Advanced Patterns
### Content Projection
```typescript
// Parent component
<app-card>
<div class="header">Card Title</div>
<div class="content">Card content</div>
</app-card>
// Card component
@Component({
selector: 'app-card',
template: `
<div class="card">
<ng-content select=".header"></ng-content>
<ng-content select=".content"></ng-content>
<ng-content></ng-content>
</div>
`
})
export class CardComponent { }
```
### ViewChild and ContentChild
```typescript
@Component({
selector: 'app-form',
template: `<app-input #firstInput></app-input>`
})
export class FormComponent implements AfterViewInit {
@ViewChild('firstInput') firstInput!: InputComponent;
ngAfterViewInit() {
this.firstInput.focus();
}
}
```
### Custom Directive
```typescript
@Directive({
selector: '[appHighlight]'
})
export class HighlightDirective {
constructor(private el: ElementRef) {
this.el.nativeElement.style.backgroundColor = 'yellow';
}
}
// Usage: <p appHighlight>Highlighted text</p>
```
## Encapsulation
### View Encapsulation Modes
```typescript
@Component({
selector: 'app-card',
template: `<div class="card">...</div>`,
styles: [`.card { color: blue; }`],
encapsulation: ViewEncapsulation.Emulated // Default
})
export class CardComponent { }
```
- **Emulated** (default): CSS scoped to component
- **None**: Global styles
- **ShadowDom**: Uses browser shadow DOM
## Change Detection
### OnPush Strategy
```typescript
@Component({
selector: 'app-user',
template: `<div>{{ user.name }}</div>`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class UserComponent {
@Input() user!: User;
constructor(private cdr: ChangeDetectorRef) {}
manualDetection() {
this.cdr.markForCheck();
}
}
```
## Provider Patterns
### Multi-Provider
```typescript
@NgModule({
providers: [
{ provide: VALIDATORS, useValue: emailValidator, multi: true },
{ provide: VALIDATORS, useValue: minLengthValidator, multi: true }
]
})
export class ValidatorsModule { }
```
### Factory Pattern
```typescript
@NgModule({
providers: [
{
provide: ConfigService,
useFactory: (env: EnvironmentService) => {
return env.production ?
new ProdConfigService() :
new DevConfigService();
},
deps: [EnvironmentService]
}
]
})
export class AppModule { }
```
## Testing Components
```typescript
describe('UserCardComponent', () => {
let component: UserCardComponent;
let fixture: ComponentFixture<UserCardComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [UserCardComponent]
}).compileComponents();
fixture = TestBed.createComponent(UserCardComponent);
component = fixture.componentInstance;
});
it('should emit deleted when delete button clicked', () => {
spyOn(component.deleted, 'emit');
component.user = { id: 1, name: 'John', email: '[email protected]' };
fixture.detectChanges();
fixture.debugElement.query(By.css('button')).nativeElement.click();
expect(component.deleted.emit).toHaveBeenCalled();
});
});
```
## Performance Optimization
1. **Use OnPush**: Reduces change detection cycles
2. **Unsubscribe**: Prevent memory leaks
3. **TrackBy**: Optimize *ngFor rendering
4. **Lazy Load**: Load modules on demand
5. **Avoid property binding in templates**: Use async pipe
```typescript
// Bad
users: User[] = [];
// Good
users$ = this.userService.getUsers();
<!-- Template -->
<app-user *ngFor="let user of users$ | async; trackBy: trackByUserId">
</app-user>
```
## Best Practices
1. **Smart vs Presentational**: Container components handle logic
2. **One Responsibility**: Each component has a single purpose
3. **Input/Output**: Use @Input/@Output for communication
4. **Services**: Handle business logic and HTTP
5. **DI**: Always use dependency injection
6. **OnDestroy**: Clean up subscriptions
## Resources
- [Angular Documentation](https://angular.io/docs)
- [Angular Best Practices](https://angular.io/guide/styleguide)
- [Component Interaction](https://angular.io/guide/component-interaction)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.