【发布时间】:2014-04-22 21:55:32
【问题描述】:
这是我的模板:
<div class="form-group"
ng-repeat="recipeIngredient in recipes.currentRecipe._ingredients">
<label class="col-sm-2 control-label">Ingredient {{ $index + 1 }}</label>
<div class="col-sm-10 form-inline" role="form">
<input
type="text"
class="form-control"
placeholder="quantity"
ng-model="recipeIngredient.quantity"
>
<input
type="text"
class="form-control"
ng-model="recipeIngredient._unit"
>
<select
class="form-control"
ng-model="recipeIngredient._unit"
ng-options="unit._id for unit in units"
/>
<select
ng-model="recipeIngredient._ingredient"
class="form-control"
ng-model="recipeIngredient._ingredient"
ng-options="ingredient._id for ingredient in ingredients"
/>
<button
type="button"
class="btn btn-default btn-xs glyphicon glyphicon-remove"
ng-click="recipes.currentRecipe.removeRecipeIngredient($index)">
</button>
</div>
</div>
我想显示当前食谱中列出的成分 如果我使用:
<input type="text" class="form-control" ng-model="recipeIngredient._unit">
我可以看到 _unit 的值显示
但是为什么选择表单根本不显示recipeIngredient._unit的当前值?
<select
class="form-control"
ng-model="recipeIngredient._unit"
ng-options="unit._id for unit in units"
/>
我已验证 _unit 是单位列表的一部分
如果我将选择框的值更改为某个值,输入文本显示“对象”,这意味着模型的实际值是单位对象而不是unit._id文本
ng-options="unit._id for unit in units"`
如果您需要其他代码,请告诉我
【问题讨论】:
-
如果你需要额外的代码,请告诉我 --> jsfiddle / plnkr 总是好的。
-
我终于找到了解决问题的方法!
标签: angularjs