Limit Angular UI-Bootstrap Typeahead to specific object property

前端 未结 1 1672
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 02:39

I have the following Angular UI-Bootstrap typeahead working great:



        
相关标签:
1条回答
  • 2021-02-04 03:19

    The typeahead directive from the http://angular-ui.github.io/bootstrap/ repo was build to well fit into existing AngularJS ecosystem. This means that this directive tries to re-use as much as possible of syntax, filters and directives already used in AngularJS.

    Back to your question - the filtering itself is done by the Angular's filter filter described here: http://docs.angularjs.org/api/ng.filter:filter The mentioned filter's syntax is flexible enough to limit searches to a selected set of properties:

    typeahead="stuff as stuff.name for stuff in stuffs | filter:{name: $viewValue}"
    

    Please notice: filter:{name: $viewValue}

    Working plunk here: http://plnkr.co/edit/o1qWKq8LSmbbmVaYkOvb?p=preview

    0 讨论(0)
提交回复
热议问题