Socket
Book a DemoInstallSign in
Socket

ng-sub

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-sub

Ng-Sub is a lightweight tool used to manage rxjs subscriptions and prevent memory leakage.

0.4.2
latest
Source
npmnpm
Version published
Weekly downloads
8
Maintainers
2
Weekly downloads
 
Created
Source

NgSub

NgSub is a lightweight tool provided by Anchor Solutions that can be used to manage RxJs subscriptions and prevent memory leakages when working, subscribe to data streams in JavaScript or any of its framework. Usable both in browser and Node.js environments.

Installation

Install ng-sub via npm by running the following command:

npm install ng-sub --save

Usage

Register the NgSubModule in your app module (or any other module you want to use it).

import { NgSub } from 'ng-sub';

const sub = new NgSub();

const observable: Observable = of(null);

// use the service with takeUntil when subscribing to any observable
observable.pipe(takeUntil(sub)).subscribe();

// Or use it to manage multiple subscriptions
sub.add(sub1, sub2, sub3);

// when done, remember to unsubscribe all subscriptions in one place
sub.unsubscribe();

Angular example

import { NgSub } from 'ng-sub';
import { Observable, of } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

@Component({
  selector: 'app-selector',
  templateUrl: '<h1>Template html</h1>',
  styleUrls: ['css path here...']
})
export class ComponentA implements OnInit, OnDestroy {
    private sub = new NgSub();

    constructor() {}

    ngOnInit(): void {
        const observable: Observable = of(null);

        // use the service with takeUntil when subscribing to any observable
        observable.pipe(takeUntil(this.sub)).subscribe();

        // Or use it to manage multiple subscriptions
        this.sub.add(sub1, sub2, sub3);
    }

    ngOnDestroy(): void {
        this.sub.unsubscribe();
    }
}

Keywords

Reactive programming

FAQs

Package last updated on 09 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.