https://github.com/netanelbasal/angular2-take-until-destroy
Declarative way to unsubscribe from observables when the component destroyed
https://github.com/netanelbasal/angular2-take-until-destroy
angular2 observables rxjs unsubscribe
Last synced: 3 months ago
JSON representation
Declarative way to unsubscribe from observables when the component destroyed
- Host: GitHub
- URL: https://github.com/netanelbasal/angular2-take-until-destroy
- Owner: NetanelBasal
- Created: 2016-11-06T12:57:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-24T07:53:42.000Z (over 7 years ago)
- Last Synced: 2025-03-17T20:45:07.169Z (3 months ago)
- Topics: angular2, observables, rxjs, unsubscribe
- Language: TypeScript
- Homepage:
- Size: 27.3 KB
- Stars: 37
- Watchers: 2
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Not maintained, use [ngx-take-until-destroy](https://github.com/NetanelBasal/ngx-take-until-destroy)
# Angular 2+ - Unsubscribe for pros
##### Declarative way to unsubscribe from observables when the component destroyed
## Installation
`npm install angular2-take-until-destroy --save`## Usage
```js
import { TakeUntilDestroy } from "angular2-take-until-destroy";@Component({
selector: 'app-inbox',
templateUrl: './inbox.component.html'
})
@TakeUntilDestroy
export class InboxComponent implements OnDestroy {
componentDestroy;
constructor( ) {
const timer$ = Observable.interval(1000)
.takeUntil(this.componentDestroy())
.subscribe(val => console.log(val))
}// If you work with AOT this method must be present, even if empty!
// Otherwise 'ng build --prod' will optimize away any calls to ngOnDestroy,
// even if the method is added by the @TakeUntilDestroy decorator
ngOnDestroy() {
// You can also do whatever you need here
}}
```