无法在ng-option中选择货币值

问题描述 投票:0回答:1

我有HTML代码

 {{cm.currency}}
  <select name="currency" id="currency" ng-model="cm.currency" class="form-control"
       ng-options="c.code as c.code +' ' +c.name for c in currencies track by  c.code">
</select>

在控制器中

 $scope.cm={currency:'INR'};
 $scope.currency=[{code: "USD" id: 1 name: "US Dollar" symbol: "$"},
             {code: "INR" id: 2 name: "Indian Rupee" symbol: "₹"},
             {code: "EUR", id: 3, name: "Euro", symbol: "€"},
            ];

{{{cm.currency}}正在使用正确的货币值,但未在ng-option中选择值

angularjs
1个回答
0
投票

这里有一些语法错误,数组中缺少逗号:

$scope.currency=[{code: "USD", id: 1, name: "US Dollar",symbol: "$"},
             {code: "INR", id: 2, name: "Indian Rupee", symbol: "₹"},
             {code: "EUR", id: 3, name: "Euro", symbol: "€"},
            ];

此外,数组的名称在模板中不正确(货币/货币):

{{cm.currency}}
  <select name="currency" id="currency" ng-model="cm.currency" class="form-control"
       ng-options="c.code as c.code +' ' +c.name for c in currency track by  c.code">
</select>
© www.soinside.com 2019 - 2024. All rights reserved.