Skip to content

Commit f2f8f45

Browse files
authored
fix(typeahead): fix updating model (#5640)
Fix updating model on focus Close #5251
1 parent 7680cce commit f2f8f45

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/typeahead/typeahead.directive.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,14 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
275275
@HostListener('focus')
276276
onFocus(): void {
277277
this.isFocused = true;
278-
if (this.typeaheadMinLength === 0) {
279-
this.typeaheadLoading.emit(true);
280-
this.keyUpEventEmitter.emit(this.element.nativeElement.value || '');
281-
}
278+
// add setTimeout to fix issue #5251
279+
// to get and emit updated value if it's changed on focus
280+
setTimeout(() => {
281+
if (this.typeaheadMinLength === 0) {
282+
this.typeaheadLoading.emit(true);
283+
this.keyUpEventEmitter.emit(this.element.nativeElement.value || '');
284+
}
285+
}, 0);
282286
}
283287

284288
@HostListener('blur')

0 commit comments

Comments
 (0)