{"id":42003122,"url":"https://github.com/w11k/ngx-componentdestroyed","last_synced_at":"2026-01-26T01:34:40.033Z","repository":{"id":24491696,"uuid":"92261734","full_name":"w11k/ngx-componentdestroyed","owner":"w11k","description":"Unsubscribe from Observables in Angular Components","archived":false,"fork":false,"pushed_at":"2022-11-08T14:46:08.000Z","size":457,"stargazers_count":95,"open_issues_count":8,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-09-03T05:56:58.325Z","etag":null,"topics":["angular","rxjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@w11k/ngx-componentdestroyed","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/w11k.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-24T07:13:03.000Z","updated_at":"2025-08-31T21:32:40.000Z","dependencies_parsed_at":"2023-01-14T01:03:57.236Z","dependency_job_id":null,"html_url":"https://github.com/w11k/ngx-componentdestroyed","commit_stats":null,"previous_names":["w11k/ng2-rx-componentdestroyed"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/w11k/ngx-componentdestroyed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w11k%2Fngx-componentdestroyed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w11k%2Fngx-componentdestroyed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w11k%2Fngx-componentdestroyed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w11k%2Fngx-componentdestroyed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w11k","download_url":"https://codeload.github.com/w11k/ngx-componentdestroyed/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w11k%2Fngx-componentdestroyed/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28763960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"ssl_error","status_checked_at":"2026-01-26T00:37:25.959Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","rxjs"],"created_at":"2026-01-26T01:34:39.969Z","updated_at":"2026-01-26T01:34:40.022Z","avatar_url":"https://github.com/w11k.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Build Status](https://travis-ci.org/w11k/ngx-componentdestroyed.svg?branch=master)](https://travis-ci.org/w11k/ngx-componentdestroyed)\n[![npm version](https://badge.fury.io/js/%40w11k%2Fngx-componentdestroyed.svg)](https://badge.fury.io/js/%40w11k%2Fngx-componentdestroyed)\n\n# Unsubscribe from Observables in Angular\n\nThis library provides utility methods which help to unsubscribe from ReactiveX's Observables in Angular applications.\n\n**If you already use this library and want to use it with Angular 9:** Please check the [Migration Guide](https://github.com/w11k/ngx-componentdestroyed#migration-guide-4xx---5xx).\n\n## Why?\n\nFailing to unsubscribe from observables will lead to unwanted memory leaks as the observable stream is left open, potentially even after a component has been destroyed or the user has navigated to another page.\n\n*Important*: If services are used in [Hierarchical Dependency Injectors](https://angular.io/guide/hierarchical-dependency-injection#hierarchical-dependency-injectors) they are affected by the same memory-leak issue!\n\nThis blog post provides additional information:\n\nhttps://medium.com/thecodecampus-knowledge/the-easiest-way-to-unsubscribe-from-observables-in-angular-5abde80a5ae3\n\n## Patrons\n\n❤️ [W11K - The Web Engineers](https://www.w11k.de/)\n\n❤️ [theCodeCampus - Trainings for Angular and TypeScript](https://www.thecodecampus.de/)\n\n## First: Check your Angular version!\n\nIf you are using Angular \u003c= 8 or Angular 9 with ViewEngine instead of Ivy, you have to use a previous version of this library. Please see [ViewEngine usage](https://github.com/w11k/ngx-componentdestroyed/blob/master/docs/viewengine.md) for further instructions. If you are using the latest Angular version and if you have no idea what ViewEngine or Ivy is, just continue with the instructions below.\n\n## Demo\n\n```\n@Component({\n    selector: 'foo',\n    templateUrl: './foo.component.html'\n})\nexport class FooComponent \n            extends OnDestroyMixin                  // \u003c--- 1. extend OnDestroyMixin \n            implements OnInit { \n\n    ngOnInit() {\n        interval(1000)\n            .pipe(\n                untilComponentDestroyed(this)       // \u003c--- 2. use the pipe operator\n            )\n            .subscribe();\n  }\n\n}\n```\n\nThe TypeScript compiler will check that your component extends `OnDestroyMixin` when you try to use `untilComponentDestroyed`.\n\n## Installation\n\n**Download the NPM package**\n\n```\nnpm i --save @w11k/ngx-componentdestroyed\n```\n## Usage\n\n### Prepare the class\n\nYour component class must extend `OnDestroyMixin`:\n\n```\nimport {OnDestroyMixin} from \"@w11k/ngx-componentdestroyed\";\n\n@Component({\n    selector: 'foo',\n    templateUrl: './foo.component.html'\n})\nexport class FooComponent extends OnDestroyMixin {  // \u003c--- HERE \n    ...\n}\n```\n\n### Use the pipe operator\n\nEither use\n\n- `untilComponentDestroyed(this)`\n- `takeUntil(componentDestroyed(this))`\n \nas the last Observable pipe operator.\n\n```\nimport {interval} from \"rxjs\";\nimport {takeUntil} from \"rxjs/operators\";\nimport {untilComponentDestroyed} from \"@w11k/ngx-componentdestroyed\";\n\n\ninterval(1000)\n    .pipe(\n        untilComponentDestroyed(this)               // \u003c--- HERE\n    )\n    .subscribe();\n```\n\n### Be careful with implementing `ngOnDestroy()`\n\nIf the component implements `ngOnDestroy()`, it must call `super.ngOnDestroy()` within the method body. \n\n\n## Migration guide 4.x.x -\u003e 5.x.x\n\n1. The component class has to extend `OnDestroyMixin` (import from `@w11k/ngx-componentdestroyed`).\n2. If the component class has a constructor (very likely), you have to call `super()` at the beginning. The TypeScript compiler will complain if you don't.\n3. You **must** either remove the existing `ngOnDestroy()` method (if empty, recommended) or call `super.ngOnDestroy()` within.\n\n## TSLint rule\n\nOur sister project [@w11k/rx-ninja](https://github.com/w11k/rx-ninja) provides a TSLint rule to enforce the use a terminator operator. If you want to use `untilComponentDestroyed(this)` instead of `takeUntil(componentDestroyed(this))` please add this configuration to your tslint.json file:\n\n```\n{\n  \"rulesDirectory\": [\n    \"node_modules/@w11k/rx-ninja/dist/tslint_rules\"\n  ],\n  \"rules\": {\n    \"rx-ninja-subscribe-takeuntil\": [true, \"takeUntil\", \"untilComponentDestroyed\"]\n  }\n}\n```\n\n## A note on Ivy, ViewEngine, AoT on/off, Karma, Jest, ...\n\nWe tried everything but the current state of Angular's Ivy compilation is a f@#!ing nightmare: \n\n- Base classes do not work with ViewEngine\n- Ivy doesn't work with patching at runtime (this library version \u003c= 4)\n- Decorator tricks rely on Angular internals and **will** break in the future ...\n- ... they don't work with Karma or Jest\n- ... but even if the don't break, they don't work with AoT compilation turned off\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw11k%2Fngx-componentdestroyed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw11k%2Fngx-componentdestroyed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw11k%2Fngx-componentdestroyed/lists"}