Angularjs:当使用ng-value时,value = 0?

时间:2015-10-20 13:42:15

标签: javascript angularjs angularjs-ng-value

我有一个奇怪的错误。当我使用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>

1 个答案:

答案 0 :(得分:1)

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

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

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