在ng-options / ng-model中设置默认选项时遇到问题。
我的问题是,当下拉列表中填充了正确的选项时,默认选项为空白。这让我相信我在做模型方面有些不对劲。有什么帮助吗?
我有一张表,我使用ng-repeat迭代一个数组:
$scope.dumpsters = [
{id:"1", sub_customer: 'a'},
{id:"2", sub_customer: 'b'},
{id:"3", sub_customer: 'c'}
]
为简单起见,我有一组独立的sub_customers:
$scope.subCustomers = [{description:'a'}, {description:'b'}, {description:'c'}];
所以现在在我的表中,每一行都有一个包含它的列:
<select ng-model="d.sub_customer" ng-options="v.description for v in subCustomers" ng-change="updateCustomer(d.sub_customer, d.id)"></select>
答案 0 :(得分:1)
在这种情况下你可以使用select as
,问题是你的语法对象引用必须匹配。假设匹配项是描述字段,您可以这样做:
<select ng-model="d.sub_customer"
ng-options="v.description as v.description for v in subCustomers"
ng-change="updateCustomer(d.sub_customer, d.id)"></select>