在 ng-repeat 中使用时,我在选择选项卡上遇到一些问题。 在 Stackoverflow 上,我找到了许多与我的问题相关的解决方案,但我无法解决我的问题。
这是我的代码.. 在页面顶部我定义了我的 Controller
<ion-view view-title="Product" ng-controller="productCtrl as pd">
在 Controller 上
self.pdata = response;
在 html 页面上我的代码是..
<div ng-if="pd.pdata.optionid.length > 0" class="prodetail" ng-repeat="x in pd.pdata.optionid">
<h5>{{x.title}}</h5>
<select name="{{x.title}}" ng-model="pd[x.title]" style="right:5px;">
<option ng-repeat="y in pd.pdata.optionvalue[x.option_id]" value="{{y.value_id}}" selected>{{y.title | uppercase}}</option>
</select>
</div>
这里我的选择选项卡位于 ng-repeat 循环中 这样每次我的 ng-model 都是动态定义的。
我的问题是:-在选择标签中使用 ng-repeat 添加了额外的空白选项
最佳答案
像这样修改你的select
标签,虽然有点拗口,但也可以,你也可以保留你的option
标签并删除ng-options
从我的 select
标签中。
<select ng-init="pd[x.title] = pd[x.title] || pd.pdata.optionvalue[x.option_id][0].value_id" name="{{x.title}}" ng-model="pd[x.title]" style="right:5px;" ng-options="y.value_id as y.title.toUpperCase() for y in pd.pdata.optionvalue[x.option_id]">
</select>
这是一个jsFiddle
关于AngularJS - 当我在选择标签中使用 ng-repeat 时添加额外的空白选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34488554/