Skip to content

Instantly share code, notes, and snippets.

@frederikprijck
Last active January 12, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederikprijck/f7a09f000f371260c372c5bedeedf0fb to your computer and use it in GitHub Desktop.
Save frederikprijck/f7a09f000f371260c372c5bedeedf0fb to your computer and use it in GitHub Desktop.
class SurveyListController {
surveys: ISurvey[];
search$: Subject<string> = new Subject<string>();
// subject used to clean up the observable subscriptions.
private onDestroy$: Subject<any> = new Subject<any>();
/**
* hook in-to the Angular onInit event
*/
$onInit() {
search$
.map(searchValue => { searchValue })
.startWith({ searchValue: ''})
.switchMap(params => this.search(params.searchValue))
// temp workaround for: https://github.com/ReactiveX/rxjs/issues/2160
.takeUntil(this.onDestroy$)
.subscribe(result => {
this.surveys = result.items;
});
}
/**
* hook in-to the Angular onDestroy event
*/
$onDestroy() {
// completing onDestroy cleans up the subscription's using onDestroy$ as takeUntil
this.onDestroy$.complete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment