i've a problem with the interact of AngularJs and MongoDb. I use NodeJs and ExpressJs on the server-side. With Mongoose i talk to Mongo. I've just done the routes.
index.js
app.get('/api/dashboard', function (req, res) {
Homepage
.find({}, 'title -_id createdBy allbids.bid endTime')
.exec(function (err, auctions) {
if(err)
res.send(err);
console.log(auctions);
res.json(auctions);
})
});
The console display all the fields that i need.
Then i pass on the front-end. I use Angular route in this way:
var app = angular.module('auction', [ 'ngRoute','HomeCtrl','NewAuctionCtrl', 'FollowingAuctionsCtrl', 'MyAuctionsCtrl']);
app.config(function ($routeProvider, $locationProvider)
{
$routeProvider
.when('/', {
templateUrl: 'views/partials/dashboard.html',
controller: 'HomeController'
})
$locationProvider.html5Mode(true);
});
And my HomeController is this:
angular.module('HomeCtrl', [])
.controller('HomeController',function ($scope, $http) {
$http.get('/api/dashboard').then(function(data) {
console.log(data);
$scope.auctions= data;
})
});
In the dashboard.html
<div class="panel panel-default" ng-controller="HomeController">
<div class="panel-heading">All The Auctions</div>
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item" ng-repeat="auction in HomeController.auctions">
{{auction}}
</li>
</ul>
</div>
It doesn't work. I need only to use {{auction.title}} instead of {{auction}}??