@writetome51/unsubscribe-on-destroy-directive
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

UnsubscribeOnDestroyDirective

An abstract Angular directive class that any Angular directive class which uses
Subscriptions can extend from.

During the ngOnDestroy() hook, it unsubscribes from all Subscriptions inside
this._subscriptions. Have your component classes that use Subscriptions
inherit from this class, add their subscriptions to this._subscriptions, then let
this class automatically unsubscribe from all of them during ngOnDestroy().

Example

export class ExamplePageComponent extends UnsubscribeOnDestroyDirective
    implements AfterViewInit {

    ngAfterViewInit() {
        this._subscriptions = this._subscriptions.concat(
            // Add any subscriptions this component is using to this array:
            [
                this.subscriptionOne,
                this.subscriptionTwo,
                // ...
            ]
        );
    }

}

Properties

protected _subscriptions: Array<{ unsubscribe: () => any }>

Methods

ngOnDestroy() : void

Installation

npm i @writetome51/unsubscribe-on-destroy-directive

Loading

import { UnsubscribeOnDestroyDirective } 
	from '@writetome51/unsubscribe-on-destroy-directive';

License

MIT

Package Sidebar

Install

npm i @writetome51/unsubscribe-on-destroy-directive

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

4.13 kB

Total Files

5

Last publish

Collaborators

  • writetome51