Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.