Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -106,5 +106,6 @@
},
"engines": {
"node": ">=6.0.0"
}
},
"dependencies": {}
}
24 changes: 18 additions & 6 deletions src/auto-complete/auto-complete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<typeof setTimeout>;
public subscription?: Subscription;
public selected:any|any[];
public selection:any;
public showSuggestions:boolean = false;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -428,7 +440,7 @@ export class AutoCompleteComponent implements AfterViewChecked, ControlValueAcce
}

if (result instanceof Observable) {
result.pipe(
this.subscription = result.pipe(
finalize(
() => {
this.isLoading = false;
Expand Down Expand Up @@ -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 {
Expand Down