|
|
@ -44,7 +44,7 @@ export const SQX_AUTOCOMPLETE_CONTROL_VALUE_ACCESSOR: any = { |
|
|
template, |
|
|
template, |
|
|
providers: [SQX_AUTOCOMPLETE_CONTROL_VALUE_ACCESSOR] |
|
|
providers: [SQX_AUTOCOMPLETE_CONTROL_VALUE_ACCESSOR] |
|
|
}) |
|
|
}) |
|
|
export class AutocompleteComponent implements Ng2Forms.ControlValueAccessor { |
|
|
export class AutocompleteComponent implements Ng2Forms.ControlValueAccessor, Ng2.OnDestroy { |
|
|
private subscription: Subscription | null = null; |
|
|
private subscription: Subscription | null = null; |
|
|
private lastQuery: string | null; |
|
|
private lastQuery: string | null; |
|
|
private changeCallback: (value: any) => void = NOOP; |
|
|
private changeCallback: (value: any) => void = NOOP; |
|
|
@ -93,6 +93,10 @@ export class AutocompleteComponent implements Ng2Forms.ControlValueAccessor { |
|
|
this.touchedCallback = fn; |
|
|
this.touchedCallback = fn; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
|
|
this.cancelRequest(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public setDisabledState(isDisabled: boolean): void { |
|
|
public setDisabledState(isDisabled: boolean): void { |
|
|
if (isDisabled) { |
|
|
if (isDisabled) { |
|
|
this.reset(); |
|
|
this.reset(); |
|
|
@ -102,13 +106,17 @@ export class AutocompleteComponent implements Ng2Forms.ControlValueAccessor { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private loadItems(query: string) { |
|
|
private cancelRequest() { |
|
|
const source = this.source; |
|
|
|
|
|
|
|
|
|
|
|
if (this.subscription != null) { |
|
|
if (this.subscription != null) { |
|
|
this.subscription.unsubscribe(); |
|
|
this.subscription.unsubscribe(); |
|
|
this.subscription = null; |
|
|
this.subscription = null; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private loadItems(query: string) { |
|
|
|
|
|
const source = this.source; |
|
|
|
|
|
|
|
|
|
|
|
this.cancelRequest(); |
|
|
|
|
|
|
|
|
if (!source) { |
|
|
if (!source) { |
|
|
return; |
|
|
return; |
|
|
|