Angularjs: 使用ng-value时,value = 0?
Angularjs: when use ng-value, value = 0?
我遇到了一个奇怪的错误。当我使用 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>
不要绑定表达式。 ngValue 使用 $eval
数据绑定,这意味着您应该删除 {{ }}
<option ng-repeat="x in makes" ng-value="x.make_id">{{x.make}}</option>
编辑: 这在 AngularJS 文档中没有很好的记录。
我遇到了一个奇怪的错误。当我使用 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>
不要绑定表达式。 ngValue 使用 $eval
数据绑定,这意味着您应该删除 {{ }}
<option ng-repeat="x in makes" ng-value="x.make_id">{{x.make}}</option>
编辑: 这在 AngularJS 文档中没有很好的记录。