diff --git a/src/app/natural-language-search/natural-language-search.component.ts b/src/app/natural-language-search/natural-language-search.component.ts index cca27f7..7c83e71 100644 --- a/src/app/natural-language-search/natural-language-search.component.ts +++ b/src/app/natural-language-search/natural-language-search.component.ts @@ -11,7 +11,8 @@ import {properties} from "../../environments/environment"; }) export class NaturalLanguageSearchComponent { - private subscriptions = []; + // private subscriptions = []; + private nlSearchSubscription = null; properties: EnvProperties = properties; showLoading: boolean = false; errorMessage: string; @@ -25,18 +26,24 @@ export class NaturalLanguageSearchComponent { } ngOnDestroy() { - this.subscriptions.forEach(subscription => { - if (subscription instanceof Subscriber) { - subscription.unsubscribe(); - } - }); + // this.subscriptions.forEach(subscription => { + // if (subscription instanceof Subscriber) { + // subscription.unsubscribe(); + // } + // }); + if (this.nlSearchSubscription instanceof Subscriber) { + this.nlSearchSubscription.unsubscribe(); + } } search() { this.queryPhrase = this.phrase; this.errorMessage = null; this.showLoading = true; - this.subscriptions.push(this.naturalLanguageSearchService.getResults(this.properties.naturalLanguageSearchAPI, this.queryPhrase).subscribe(data => { + if(this.nlSearchSubscription) { + this.nlSearchSubscription.unsubscribe(); + } + this.nlSearchSubscription = this.naturalLanguageSearchService.getResults(this.properties.naturalLanguageSearchAPI, this.queryPhrase).subscribe(data => { if(data && data['columns']) { for(let i = 0; i < data['columns'].length - 1; i++) { if(data['columns'][i] == 'id') { @@ -54,6 +61,6 @@ export class NaturalLanguageSearchComponent { this.errorMessage = 'Sorry, something went wrong. Please try again later.'; } this.showLoading = false; - })); + }); } } \ No newline at end of file