-
-
Save navix/b65eb82fc27efaa142d7d7e1bf78716f to your computer and use it in GitHub Desktop.
Revisions
-
xtianjohns renamed this gist
Jun 4, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
xtianjohns revised this gist
Jun 4, 2017 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,20 +10,22 @@ import 'rxjs/add/operator/takeUntil'; selector: 'my-rad-component', }) export class MyComponent implements OnInit, OnDestroy { /* A subject for monitoring the destruction of the component. */ private destroyed$: Subject<{}> = new Subject(); /* Inject a service with an observable API. */ constructor(private myService: MyService) { } ngOnInit() { this.myService.getData() /* Fetch some data. */ .takeUntil( this.destroyed$ ) /* Unsubscribe from the stream upon destruction. */ .subscribe( data => { // do something with your data, AKA: define your effects. }); } ngOnDestroy() { this.destroyed$.next(); /* Emit a notification on the subject. */ } } -
xtianjohns revised this gist
Jun 4, 2017 . No changes.There are no files selected for viewing
-
xtianjohns created this gist
Jun 4, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject'; import { MyService } from './MyService.ts'; import 'rxjs/add/operator/takeUntil'; @Component({ selector: 'my-rad-component', }) export class MyComponent implements OnInit, OnDestroy { /* A subject for monitoring the destruction of the component. */ private destroyed$: Subject<{}> = new Subject(); constructor(private myService: MyService) { } ngOnInit() { this.myService.getData() .takeUntil( this.destroyed$ ) .subscribe( data => { // do something with your data }); } ngOnDestroy() { this.destroyed$.next(); } }