Skip to content

AreebaAroosh/ngx-take-until-destroy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Build Status npm

๐Ÿค“ Angular - Unsubscribe For Pros ๐Ÿ’ช

Declarative way to unsubscribe from observables when the component destroyed

Installation

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

Usage

import { TakeUntilDestroy } from "ngx-take-until-destroy";

@TakeUntilDestroy
@Component({
  selector: 'app-inbox',
  templateUrl: './inbox.component.html'
})
export class InboxComponent implements OnDestroy {
  componentDestroyed$: Subject<boolean>;

  ngOnInit( ) {
    Observable.interval(1000)
      .takeUntil(this.componentDestroyed$)
      .subscribe(val => console.log(val))
  }

  // If you work with AOT this method must be present, even if empty! 
  // Otherwise 'ng build --prod' will optimize away any calls to ngOnDestroy, 
  // even if the method is added by the @TakeUntilDestroy decorator
  ngOnDestroy() {
    // You can also do whatever you need here
  }

}

About

๐Ÿค“ Class decorator that adds takeUntil component destroyed functionality ๐Ÿ™

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors