我正在尝试从下拉列表中选择一个值,并从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的初始值?
谢谢
解决方法
根据
ui-select FAQ,你的ng-model表达式应该有一个.在其中,例如:
<ui-select ng-model="model.customer" theme="selectize">
要设置初始值,您只需设置ng-model中指定的属性,因此在控制器中:
$scope.model = { customer: $scope.customers[0] // set the initial selected option };
对于onchange事件,你可以使用$scope.$watch()如下:
$scope.$watch('model.customer',function (customer) { $scope.setActiveCustomer(customer); });
希望这可以帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。