angular-reactive
Installation
SKILL.md
Angular Reactive Programming
Version: Angular 21 (2025) Tags: Reactive, Observables, RxJS, BehaviorSubject
References: Reactive Guide • RxJS
Best Practices
- Use BehaviorSubject for state
@Injectable({ providedIn: 'root' })
export class StateService {
private state = new BehaviorSubject<State>(initialState);
state$ = this.state.asObservable();
updateState(newState: Partial<State>) {
this.state.next({ ...this.state.value, ...newState });
}
}
- Use Observable in services
@Injectable({ providedIn: 'root' })
export class DataService {
private http = inject(HttpClient);
getData(): Observable<Data[]> {
return this.http.get<Data[]>('/api/data');
}
}
- Use async pipe
@Component({
template: `
@if (data$ | async; as data) {
{{ data.name }}
}
`
})
export class MyComponent {
data$ = this.service.getData();
}
- Use shareReplay for caching
data$ = this.http.get('/api/data').pipe(
shareReplay(1)
);
- Use takeUntil for cleanup
@Component({})
export class MyComponent implements OnDestroy {
private destroy$ = new Subject<void>();
ngOnInit() {
this.data$.pipe(takeUntil(this.destroy$)).subscribe();
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
Related skills
More from oguzhan18/angular-ecosystem-skills
angular-tailwind
ALWAYS use when working with Angular and Tailwind CSS, Tailwind configuration, utility-first CSS, or styling Angular applications with Tailwind.
139angular-animations
>-
137rxjs
ALWAYS use when working with RxJS Observables, operators, and reactive patterns in Angular applications.
135angular-material
ALWAYS use when working with Angular Material components, CDK, or Material Design in Angular applications.
131angular-security
ALWAYS use when working with Angular Security, XSS prevention, CSRF protection, Content Security Policy, or sanitization in Angular applications.
130angular-bootstrap
ALWAYS use when working with Angular Bootstrap, ng-bootstrap, Bootstrap components in Angular, or Bootstrap 5 integration.
129