3

我遇到了一个奇怪的错误。当我使用 ng-value 时,页面会为某些选项呈现“value=0”。控制台不显示错误。

这是代码:

<option ng-repeat="x in makes" ng-value="{{x.make_id}}">{{x.make}}</option>

结果如下:

<option ng-repeat="x in makes" ng-value="acura" class="ng-binding ng-scope">ACURA</option>
<!-- end ngRepeat: x in makes -->
<option ng-repeat="x in makes" ng-value="alfa-romeo" class="ng-binding ng-scope" value="0">ALFA ROMEO</option>
<!-- end ngRepeat: x in makes -->
<option ng-repeat="x in makes" ng-value="alpina" class="ng-binding ng-scope">ALPINA</option>
<!-- end ngRepeat: x in makes -->
<option ng-repeat="x in makes" ng-value="armstrong-siddeley" class="ng-binding ng-scope" value="0">ARMSTRONG SIDDELEY</option>
4

1 回答 1

1

不要绑定表达式。ngValue 使用$eval数据绑定,这意味着您应该删除{{ }}

<option ng-repeat="x in makes" ng-value="x.make_id">{{x.make}}</option>

编辑:这在 AngularJS 文档中没有很好地记录。

于 2015-10-20T13:48:46.837 回答