Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 为选择输入设置所选值_Angularjs - Fatal编程技术网

Angularjs 为选择输入设置所选值

Angularjs 为选择输入设置所选值,angularjs,Angularjs,我有两个目标-订单和客户。现在我想编辑订单。订单具有来自客户对象的两个文件。我想在选择选项中显示客户列表: select(ng-model="customer" ng-options="customer.description for customer in vm.customers" ng-change="vm.setCustomer(customer)") 以下是控制器中的setCustomer方法: setCustomer = function(custome

我有两个目标-订单和客户。现在我想编辑订单。订单具有来自客户对象的两个文件。我想在选择选项中显示客户列表:

select(ng-model="customer"
       ng-options="customer.description for customer in vm.customers"
       ng-change="vm.setCustomer(customer)")
以下是控制器中的setCustomer方法:

setCustomer = function(customer) {
   this.currentOrder.customerId = customer.autoincrementedId;
   this.currentOrder.customerDescription = customer.description;
}
这就是工作。我可以从列表中选择Customer,它将填充currentOrder对象中的两个字段

但当我加载页面时,我的选择控件是空的,即使我在订单中填写了customerId和customerDescription。我知道原因是客户是空的,但我不知道最好的解决方法是什么

如何在打开页面时填写选择?

在ngOptions的arr语法中将该值用作obj的文本-然后将ngModel设置为以下值:


并将this.customer设置为您希望默认选择的客户的AutoIncrementeId。

使用此内部函数时要小心,应存储引用在这种情况下,我将仅将id传递给我的函数vm.setCustomercustomer,并且不能在其中设置第二个字段。我可以通过id在我的收藏中找到客户,但可能有更好的方法吗?@demas-我更新了答案以使用autoincrementedId之前没有看到它-加载-将此分配给客户您想要选择的autoincrementedId。
select(ng-model="customer"
   ng-options="customer.autoincrementedId as customer.description for customer in vm.customers"
   ng-change="vm.setCustomer(customer)")