2017-01-22 74 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模型