Angularjs 将数据发送到ui上的控制器。选择“角度”
我试图从下拉列表中选择一个值,并从angularJs中对应的select id中获取数据 我已经提出了指令Angularjs 将数据发送到ui上的控制器。选择“角度”,angularjs,angularjs-directive,ui-select2,Angularjs,Angularjs Directive,Ui Select2,我试图从下拉列表中选择一个值,并从angularJs中对应的select id中获取数据 我已经提出了指令 <ui-select ng-model="customer" theme="selectize"> <ui-select-match placeholder="Customer List">{{$select.selected.Name}}</ui-select-match>
<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>
我的问题是
- 一旦我选择了客户,我应该使用哪个事件进行fire
setActiveCustomer(比如onchange之类的)。当我使用
事件多次激发,因为ng时,单击
ng单击
以激活控件
- 另一个问题是如何设置初始值
ng型号
表达式中应该有一个
,例如:
<ui-select ng-model="model.customer" theme="selectize">
对于onchange事件,您可以像这样使用$scope.$watch()
:
$scope.$watch('model.customer', function (customer) {
$scope.setActiveCustomer(customer);
});
希望这能有所帮助。Hi runTarmit令人惊讶地解决了我的第一个问题,但第二个问题仍然困扰着我。你是说设置初始值吗?是的。初始值未按预期分配!!您能否演示如何使用设置
$scope.model.customer
?$scope.customers
当时可用吗?是的,它可用,但当它绑定到选择ui时,它只显示[object object object]我用firebug检查了这些对象,它显示初始绑定的对象是[object{Id=1,Name=“FirstOne”}]
,但它应该类似于object{Id=1511,Name=“FirstOne”,$$hashKey=“00H”}
$scope.model = {
customer: $scope.customers[0] // set the initial selected option
};
$scope.$watch('model.customer', function (customer) {
$scope.setActiveCustomer(customer);
});