2017-01-22 71 views
0

我有选择框,其中我使用角常量传递数据。我得到了两种不同的类型,我是如何写的,因为我试图解决我的问题,但没有成功。问题是我的选择框不会将任何值传递给post请求,我不知道为什么。我也尝试过使用ng-option但结果相同。AngularJS选择选项不传递值到http post请求

(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, 
    } 

这是我的视图,其中i使用这些数据从我的控制器来为我的形式。我用NG-重复根据官方的角度文档: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> 

我失去的东西,为什么它不能正常工作?

回答

0

你的状态是一个对象,你没有任何id

使用NG选项

<select ng-model="status.model" ng-options="key as value for (key , value) in status.options"> 
</select> 

或NG重复这样的:

<select ng-model="status.model"> 
    <option ng-repeat="(key, value) in status.options" value="{{key}}">{{value}}</option> 
</select> 
+0

感谢响应快,我想这可惜它不是为我工作。它仍然发送除了我的值从这些选择框中的一切。它在我的代码中一定是一些愚蠢的错误,但我现在无法看到它。 – Martin

+0

@Martin请创建你的代码的更多帮助 –

+0

我已经解决了。我犯了一个愚蠢的错误。我将我的选择框分配给错误的模型。我在ng-inspector中检查了一下,我安装并看到它。 我不得不使用这个ng模型