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

后端 未结 11 1528
孤街浪徒
孤街浪徒 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:32

    I wanted something like the OP's description and the only solution I found was to come up with a template that combines the dropdown and typeahead directives - maybe the OP or someone else will find it useful:

    angular.module('app', ['ui.bootstrap'])
    .controller('AppCtrl', function($scope) {
      $scope.model;
      $scope.options = [{label:'Option 1'}, {label:'Option 2'}, {label:'Option 3'}];
      
      $scope.onSelect = function($item, $model, $label) {
        $scope.model = angular.copy($item);
      }
    });
    
    
    
    
    

    Of course, you could simplify it to make the options just an array of strings- I made them objects because that was more like what I needed.

提交回复
热议问题