AGENT SKILL

angular-destroyref

ALWAYS use when working with Angular DestroyRef, takeUntilDestroyed, or cleanup in Angular.

License 许可
MIT
最近更新
2026-06-10
Stars
★ 3
Forks
0

01 前言 Front Matter

name
angular-destroyref
metadata
{ "version": "21.0.0", "generated_at": 1771459200000, "generated_by": "oguzhancart" }
description
ALWAYS use when working with Angular DestroyRef, takeUntilDestroyed, or cleanup in Angular.

03 SKILL.md 正文

Angular DestroyRef

Version: Angular 16+ (2025) Tags: DestroyRef, Cleanup, takeUntilDestroyed

References: DestroyRef

Best Practices

  • Use takeUntilDestroyed
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({})
export class MyComponent {
  private destroyRef = inject(DestroyRef);
  
  ngOnInit() {
    this.data$.pipe(
      takeUntilDestroyed(this.destroyRef)
    ).subscribe();
  }
}
  • Use in service
@Injectable({ providedIn: 'root' })
export class DataService {
  private destroyRef = inject(DestroyRef);
  
  getData() {
    return this.http.get('/api/data').pipe(
      takeUntilDestroyed(this.destroyRef)
    );
  }
}

04 同仓库更多 Skills