我遇到了AngularJS和MongoDb的交互问题。 我在服务器端使用NodeJS和ExpressJS。我用Mongoose跟Mongo说话。 我刚刚完成了路线。AngularJS显示MongoDB数据
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);
})
});
控制台显示我需要的所有领域。
然后我通过前端。我用角路线是这样的:
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);
});
而且我的HomeController是这样的:
angular.module('HomeCtrl', [])
.controller('HomeController',function ($scope, $http) {
$http.get('/api/dashboard').then(function(data) {
console.log(data);
$scope.auctions= data;
})
});
在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>
它不工作。我只需要使用{{auction.title}}
而不是{{auction}}
??
更改为“拍卖中的拍卖”。在使用$ scope时,您不需要引用控制器。 编辑:然后像你评论得到像{{auction.title}}标题。 – Mickers