angularjs – 在ui.select angular上将数据发送到控制器
发布时间:2020-12-17 07:08:13 所属栏目:安全 来源:网络整理
导读:我正在尝试从下拉列表中选择一个值,并从angularJs中的相应选择ID中获取数据 我已经提出了angular-ui/ui-select指令 ui-select ng-model="customer" theme="selectize" ui-select-match placeholder="Customer List"{{$select.selected.Name}}/ui-select-matc
我正在尝试从下拉列表中选择一个值,并从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; }); }; 我的问题是 >一旦我选择了客户哪个事件我应该用于火灾 谢谢 解决方法
根据
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); }); 希望这可以帮助. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |