angularjs – 在ui.select angular上将数据发送到控制器

我正在尝试从下拉列表中选择一个值,并从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);
});

希望这可以帮助.

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...