diff --git a/package-lock.json b/package-lock.json index 4bc631a8..7c0d4c7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4052,12 +4052,6 @@ "picocolors": "^1.0.0" } }, - "caniuse-lite": { - "version": "1.0.30001314", - "resolved": "https://artifactory.bullhorn.com/api/npm/bh-npm/caniuse-lite/-/caniuse-lite-1.0.30001314.tgz", - "integrity": "sha1-Zcf5+35FlPygozO+wdiTlmI3dZY=", - "dev": true - }, "chalk": { "version": "4.1.2", "resolved": "https://artifactory.bullhorn.com/api/npm/bh-npm/chalk/-/chalk-4.1.2.tgz", @@ -6880,9 +6874,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001314", - "resolved": "https://artifactory.bullhorn.com/api/npm/bh-npm/caniuse-lite/-/caniuse-lite-1.0.30001314.tgz", - "integrity": "sha1-Zcf5+35FlPygozO+wdiTlmI3dZY=", + "version": "1.0.30001393", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001393.tgz", + "integrity": "sha512-N/od11RX+Gsk+1qY/jbPa0R6zJupEa0lxeBG598EbrtblxVCTJsQwbRBm6+V+rxpc5lHKdsXb9RY83cZIPLseA==", "dev": true }, "canonical-path": { @@ -18164,9 +18158,9 @@ "dev": true }, "typescript": { - "version": "4.6.2", - "resolved": "https://artifactory.bullhorn.com/api/npm/bh-npm/typescript/-/typescript-4.6.2.tgz", - "integrity": "sha1-/hLScntwj07vQPUVmLM5i6qWEdQ=", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", + "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", "dev": true }, "ua-parser-js": { diff --git a/package.json b/package.json index 2bbc9b53..e7d3df2e 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "ts-node": "~8.10.2", "tslib": "^2.3.1", "tslint": "~6.1.3", - "typescript": "^4.6.2", + "typescript": "^4.3.5", "webpack": "^4.46.0", "zone.js": "^0.11.5" }, @@ -106,5 +106,6 @@ }, "engines": { "node": ">=6.0.0" - } + }, + "dependencies": {} } diff --git a/src/auto-complete/auto-complete.component.ts b/src/auto-complete/auto-complete.component.ts index 39f0941e..6de54a35 100644 --- a/src/auto-complete/auto-complete.component.ts +++ b/src/auto-complete/auto-complete.component.ts @@ -9,11 +9,12 @@ import { HostListener, ElementRef, AfterViewChecked, - ViewContainerRef + ViewContainerRef, + OnDestroy } from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; -import {from, Observable, Subject} from 'rxjs'; +import {from, Observable, Subject, Subscription, TimeoutError} from 'rxjs'; import {finalize} from 'rxjs/operators'; import {AutoCompleteOptions} from '../auto-complete-options.model'; @@ -34,14 +35,15 @@ import {AutoCompleteStyles} from '../auto-complete-styles.model'; ], templateUrl: 'auto-complete.component.html' }) -export class AutoCompleteComponent implements AfterViewChecked, ControlValueAccessor, DoCheck { +export class AutoCompleteComponent implements AfterViewChecked, ControlValueAccessor, DoCheck, OnDestroy { public autocompleteOptions:AutoCompleteOptions = new AutoCompleteOptions(); public defaultOpts:AutoCompleteOptions; public hasFocus:boolean = false; public isLoading:boolean = false; public focusedOption:number = -1; public formValue:any; - public promise; + public promise: ReturnType; + public subscription?: Subscription; public selected:any|any[]; public selection:any; public showSuggestions:boolean = false; @@ -250,6 +252,10 @@ export class AutoCompleteComponent implements AfterViewChecked, ControlValueAcce this.suggestions = []; } + ngOnDestroy():void { + this.subscription?.unsubscribe(); + } + ngAfterViewChecked():void { if (this.showListChanged) { this.showListChanged = false; @@ -379,6 +385,7 @@ export class AutoCompleteComponent implements AfterViewChecked, ControlValueAcce this.keyword = ''; this.selection = null; this.formValue = null; + this.getItems(); if (this.focusedOption > 0) { this.focusedOption = this.focusedOption - 1; @@ -400,6 +407,11 @@ export class AutoCompleteComponent implements AfterViewChecked, ControlValueAcce clearTimeout(this.promise); } + if( this.subscription) { + this.subscription.unsubscribe(); + this.subscription = undefined; + } + this.promise = setTimeout( () => { if (event) { @@ -428,7 +440,7 @@ export class AutoCompleteComponent implements AfterViewChecked, ControlValueAcce } if (result instanceof Observable) { - result.pipe( + this.subscription = result.pipe( finalize( () => { this.isLoading = false; @@ -528,7 +540,7 @@ export class AutoCompleteComponent implements AfterViewChecked, ControlValueAcce /** * Handles tab key press. * If `selectOnTabOut` is `true`, will select currently focused item - * + * * @param event */ public handleTabOut(event):void {