Angular JS - Automatically focus input and show typeahead dropdown - ui.bootstrap.typeahead

后端 未结 11 1540
孤街浪徒
孤街浪徒 2020-11-30 03:07

I am using Angular JS - ui.bootstrap.typeahead:

I would like to click a button and focus an input field and automatically show the typeahead suggestion dropdown. I h

11条回答
  •  悲哀的现实
    2020-11-30 03:50

    Now, as I don't have enough reputation to comment, I must write a new answer to warn people about runTarm's answer above. This is a viable solution, but it runs the risk of running into the following error:

    Error: [$rootScope:inprog] $apply already in progress
    

    This seems to be due to ng-focus being a synchronized event (see discussion here). Instead, one can use the ng-click-attribute, and this error doesn't occur.

    Also, I've verified that

    $element.triggerHandler('input');
    

    works just as good as the jQuery-trigger in runTarm's answer.

提交回复
热议问题