【发布时间】:2014-08-15 11:20:53
【问题描述】:
我正在尝试从下拉列表中选择一个值并从 angularJs 中对应的选择 id 中获取数据
我想出了angular-ui/ui-select 指令
<ui-select ng-model="customer" theme="selectize">
<ui-select-match placeholder="Customer List">{{$select.selected.Name}}</ui-select-match>
<ui-select-choices repeat="customer in customers | filter: $select.search">
<span ng-bind-html="customer.Name | highlight: $select.search"></span>
<small ng-bind-html="customer.Id.toString() | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
在我的控制器上我有获取客户方法
$scope.setActiveCustomer = function(customer) {
customersService.getCustomers(customer).then(function(response) {
$scope.selectedCustomer = response;
});
};
我的问题是
-
一旦我选择了客户我应该使用哪个事件来触发火灾 setActiveCustomer (比如 onchange 什么的)。当我使用
ng-click事件触发了很多次,因为ng-click用于控制激活。 -
另一件事是如何为ui-select 设置初始值?
谢谢
【问题讨论】:
标签: angularjs angularjs-directive ui-select2