Search code examples
javascriptngx-bootstrap

opening ngx-bootstrap typeahead on focus


Is there any way to open the ngx-typeahead when a user enters the input. In other words, on focus

enter image description here

I can get the dropdown to open if I type a single character into the input box, and then hit backspace.

enter image description here


Solution

  • Setting [typeaheadMinLength]="0" is the way to do this, but it also has the side effect of triggering a search even when nothing is typed in yet. I my case I needed to run the search on focus, but only if the textbox already had some content. I did this using a reference to the input's value:

    <input #searchBox
    [typeaheadMinLength]="searchBox.value?.length > 0 ? 0 : 1"
    />