This package has been deprecated

Author message:

Important: For Angular v9+ please use the until-destroy library: https://github.com/ngneat/until-destroy\#use-with-ivy

ngx-take-until-destroy
TypeScript icon, indicating that this package has built-in type declarations

5.4.0 • Public • Published

npm Build Status npm Awesome

🤓 Angular - Unsubscribe For Pros 💪

Declarative way to unsubscribe from observables when the component destroyed

Installation

npm install ngx-take-until-destroy --save

Usage

import { untilDestroyed } from 'ngx-take-until-destroy';
 
@Component({
  selector: 'app-inbox',
  templateUrl: './inbox.component.html',
})
export class InboxComponent implements OnInit, OnDestroy {
  ngOnInit() {
    interval(1000)
      .pipe(untilDestroyed(this))
      .subscribe(val => console.log(val));
  }
 
  // This method must be present, even if empty.
  ngOnDestroy() {
    // To protect you, we'll throw an error if it doesn't exist.
  }
}

Use with any class

import { untilDestroyed } from 'ngx-take-until-destroy';
 
export class Widget {
  constructor() {
    interval(1000)
      .pipe(untilDestroyed(this, 'destroy'))
      .subscribe(console.log);
  }
 
  // The name needs to be the same as the decorator parameter
  destroy() {}
}

Live example

Readme

Keywords

none

Package Sidebar

Install

npm i ngx-take-until-destroy

Weekly Downloads

6,143

Version

5.4.0

License

MIT

Unpacked Size

37.3 kB

Total Files

22

Last publish

Collaborators

  • netbasal