Question

I am having troubles getting the database information back into the controller.

My controller calls the geek service, with

$scope.dataValues = Geek.get();

The service then does:

    get : function() {
        return $http.get('/api/geeks');
    },

Then my route does.

app.get('/api/geeks', function(req, res) {

    // use mongoose to get all nerds in the database
    Route.find({},function(err,docs) {
        res.json(docs);
    });

});

What I am confused on, when the call gets back to the controller, there is nothing there and the page looks like. http://prntscr.com/3g0whh .

If i put a console.info(docs) in the routes, it prints out.

However it doesn't seem to get back to the controller, which makes the dataValues = {}

[ { _id: '53639917f4ae962320d1711a',
    MailItem: 
     { objectId: 'ObjectRef',
       volume: '100',
       weight: '5',
       priority: 'InternationalAir',
       route: '',
       dateEntered: 'Thursday',
       timeEntered: '20/05/1415:35',
       price: '7.50',
       dimension: { height: '4', width: '4', length: '4' } } } ]

Geek.html

<ul>
    <li ng-repeat="mailItem in dataValues">
        {{mailItem.price}}
    </li>
</ul>

{{dataValues}}
Was it helpful?

Solution

$http.get returns a promise so you need to use the promise api.

Try this instead;

Geek.get().then(function(response){
   $scope.dataValues = response.data;
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top