Skip to content
Class decorator that will automatically unsubscribe from observables
Branch: master
Clone or download
Latest commit dbd2f1d Jul 14, 2019

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


npm install ngx-auto-unsubscribe --save


import { AutoUnsubscribe } from "ngx-auto-unsubscribe";

  selector: 'inbox'
export class InboxComponent {
  one: Subscription;
  two: Subscription;

  constructor( private store: Store<any>, private element : ElementRef ) {}

  ngOnInit() { ="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


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

You can’t perform that action at this time.