ngx-auto-unsubscribe
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

Angular - Auto Unsubscribe For Pros

npm Build Status Build Status npm Awesome

Class decorator that will automatically unsubscribe from observable subscriptions when the component is destroyed

Installation

npm install ngx-auto-unsubscribe --save

Usage

import { AutoUnsubscribe } from "ngx-auto-unsubscribe";
 
@AutoUnsubscribe()
@Component({
  selector: 'inbox'
})
export class InboxComponent {
  one: Subscription;
  two: Subscription;
 
  constructor( private store: Store<any>, private element : ElementRef ) {}
 
  ngOnInit() {
    this.one = store.select("data").subscribe(data => // do something);
    this.two = Observable.interval.subscribe(data => // do something);
  }
 
  // This method must be present, even if empty.
  ngOnDestroy() {
    // We'll throw an error if it doesn't
  }
}

Options

Option Description Default Value
arrayName unsubscribe from subscriptions only in specified array ''
blackList an array of properties to exclude []
event a name of event callback to execute on ngOnDestroy

Note: blackList is ignored if arrayName is specified.

Similar projects

You can also use https://github.com/NetanelBasal/ngx-take-until-destroy.

/ngx-auto-unsubscribe/

    Package Sidebar

    Install

    npm i ngx-auto-unsubscribe

    Weekly Downloads

    4,438

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    14.1 kB

    Total Files

    14

    Last publish

    Collaborators

    • netbasal