首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Angularjs ui-select下拉菜单选择函数调用问题

Angularjs ui-select下拉菜单选择函数调用问题
EN

Stack Overflow用户
提问于 2015-02-12 16:22:50
回答 1查看 49.2K关注 0票数 19

在我的AngularJS项目中,我使用普通的select下拉菜单,并使用ng-change进行函数调用,它工作得很好。现在,我想将相同的下拉列表迁移到ui-select。但on-select函数调用不起作用,我尝试了不同的方法,但没有成功。请找到我的plnkr

以下是我尝试使用ui-select的两种方式:

<ui-select ng-model="uiSelectedCustomer" theme="select2" on-select="getDataBasedonCustomer(uiSelectedCustomer)" style="min-width: 300px;">
    <ui-select-match placeholder="Select a customer..">{{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="cust in customers | filter: $select.search">
        <div ng-bind-html="cust.name | highlight: $select.search"></div>
    </ui-select-choices>
</ui-select>


<ui-select ng-model="uiSelectedCustomer" theme="select2" on-select="getDataBasedonCustomer(uiSelectedCustomer)" style="min-width: 300px;">
    <match placeholder="Select a customer in the list or search his name ">{{$select.selected.name}}</match>
    <choices repeat="cust in customers | filter: $select.search">
        <div ng-bind-html="cust.name | highlight: $select.search"></div>
    </choices>
</ui-select>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-27 05:41:07

我从您的代码中了解到,您希望选择项目并根据选择执行某些操作,如果是这样,则将on-select="onSelected($item)"添加到ui-select和控制器中:

$scope.onSelected = function (selectedItem) {
  // do selectedItem.PropertyName like selectedItem.Name or selectedItem.Key 
  // whatever property your list has.
}
票数 57
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28472529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档