我有选择框,我在其中使用角度常数传递数据。我有两种不同的书写方式,因为我试图解决自己的问题,但未成功。问题是我的选择框没有将任何值传递到发布请求中,我也不知道为什么。我也尝试使用ng-option,但结果相同。
(function () {
app.constant("Constants", {
Status: {
1 : "New",
2 : "Active",
3 : "OnHold",
4 : "Testing",
5 : "Finished",
6 : "Dropped"
},
Priority: [
{ id: "1", name: "Low" },
{ id: "2", name: "Medium" },
{ id: "3", name: "High" },
{ id: "4", name: "Urgent" },
],
});
在这里我将这些枚举绑定到我的角度控制器中的范围
$scope.priority = {
model: null,
options: Constants.Priority,
}
$scope.status = {
model: null,
options: Constants.Status,
}
这是我的观点,在这里我将来自控制器的数据用于表单。我根据官方的角度文档使用ng-repeat:https : //docs.angularjs.org/api/ng/directive/select
<div class="form-group">
<label>Select Status</label>
<select name="status_select" id="status_select" ng-model="status.model" class="form-control">
<option ng-repeat="x in status.options" value="{{x.id}}">{{x}}</option>
</select>
</div>
我是否缺少某些东西,为什么它无法正常工作?
您的状态是一个对象,您没有任何对象id
!
期权的使用
<select ng-model="status.model" ng-options="key as value for (key , value) in status.options">
</select>
或ng-repeat像这样:
<select ng-model="status.model">
<option ng-repeat="(key, value) in status.options" value="{{key}}">{{value}}</option>
</select>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句