Skip to content

Instantly share code, notes, and snippets.

@pramoth
Last active September 2, 2018 17:23
Show Gist options
  • Select an option

  • Save pramoth/ebcd1c6022c3ed1584e494a82521f2ef to your computer and use it in GitHub Desktop.

Select an option

Save pramoth/ebcd1c6022c3ed1584e494a82521f2ef to your computer and use it in GitHub Desktop.
import { Component, OnInit, OnDestroy } from '@angular/core';
import { MyServiceService } from '../my-service.service';
//import from gt-unsubscribe-on-detroy
import { unsubscribeOnDetroy } from 'gt-unsubscribe-on-detroy';
@Component({
selector: 'app-b',
templateUrl: './b.component.html',
styleUrls: ['./b.component.css']
})
export class BComponent implements OnInit, OnDestroy {
constructor(private singletonService: MyServiceService) { }
ngOnInit() {
//unsubscribeOnDetroy() accept only instance of OnDestroy
this.singletonService.mySubject.pipe(unsubscribeOnDetroy(this))
.subscribe();
}
ngOnDestroy(): void {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment