AngularJS BootstrapUI Typeahead with object & selection functionality

后端 未结 6 1305
有刺的猬
有刺的猬 2020-12-24 06:17

I\'m trying to implement a typeahead in Angular using http://angular-ui.github.io/bootstrap/, where the typeahead field displays full addresses but once clicked another fiel

6条回答
  •  醉酒成梦
    2020-12-24 07:04

    @pkozlowski-opensource 's great solution has one drawback: you can't initialise the typeahead from the ng-model property in this way, at least if you want it to display the item's description and not its code.

    I found a way to solve this by configuring the typeahead like this:

    
    

    This returns a state object to the model property which can be initialised by setting the value to the appropriate object:

        $scope.selected = {postcode:'M1',address:'Manchester'};
    

    Working fiddle here: https://jsfiddle.net/0y3ntj4x/3/

    I think this scenario is missing from the angular-bootstrap documentation for the typeahead.

提交回复
热议问题