0

A simple question, I'm sure ...

I am trying to create a and load it with values from my MongoDB. From colsole.log I am sure that the query is being executed as expected but the is being populated with ...

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}

The select angular/html

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

And the Controller

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

Thanks in advance.

1
  • 3
    $http.get("/utility/monthList").then(function (response) {$scope.months = response.data }); Commented Jun 28, 2016 at 20:37

2 Answers 2

3

Since $http.get returns a promise you need to update the response when the promise is resolved:

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

Read more about promises.

Sign up to request clarification or add additional context in comments.

Comments

1

Here is a plnkr which illustrate your solution, I hope this helps you.

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>

1 Comment

Thanks Deepanjan. The plinkr demo was very useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.