2016-06-28 47 views
0

一個簡單的問題,我敢肯定...Angular/javascript:從GET中讀取值

我想創建一個並使用我的MongoDB中的值加載它。 從colsole.log我相信,正在執行的查詢如預期,但正與填充...

function (a){Qa(a,"fn");h.then(function(b){a(b.data,b.status,b.headers,f)}); return h} 
function (a){Qa(a,"fn");h.then(null,function(b){a(b.data,b.status,b.headers,f)}); return h} 

的選擇角/ HTML

<select ng-model="selected" ng-options="opt as opt for opt in months" ng-init="selected='March'"></select> 

和控制器

$scope.months = $http.get("/utility/monthList"); 

在此先感謝。

+3

$ http.get( 「/效用/ monthList」),那麼(功能(響應){$ scope.months = response.data})。 –

回答

1

這是一個說明你的解決方案的plnkr,我希望這可以幫助你。

http://plnkr.co/edit/50q9N6TmU7ubouMcgenW?p=preview

<select ng-model="selected" ng-options="opt as opt.FirstName for opt in months" ng-init="selected='March'"></select> 
+0

謝謝Deepanjan。 該plinkr演示非常有用 – richardfr

+0

快樂的編碼:)你可以請投票了,謝謝你這麼多... – Deepanjan

3

由於$http不用彷徨返回你需要更新的響應時,承諾解決一個承諾:

$http.get("/utility/monthList").then(function(res){ $scope.months = res.data; }); 

瞭解更多關於promises

+0

謝謝埃米爾 - 我已經爲稍後的承諾添加了書籤... – richardfr