我已经创建了一个nodejs应用程序,该程序将读取我mongo Db中的所有数据库,在控制台上可以实现。但是,当我尝试将数据解析为json对象并将其显示到屏幕上时,我无法使信息显示。希望有人能帮助我找出原因或告诉我我做错了什么。谢谢
app.js
app.js
// listen for get request, aka transfers the info in mongo to client
app.get('/databases', function (req, res) {
console.log("-- recived GET request --");
db.open(function(err, db) {
// Use the admin database for the operation
var adminDb = db.admin();
// List all the available databases
adminDb.listDatabases(function(err, dbs) {
assert.equal(null, err);
assert.ok(dbs.databases.length > 0);
console.log(dbs);
res.json(dbs);
db.close();
});
});
});
controller.js
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
console.log("controller connected");
function refresh(){
// create route
$http.get('/databases').success(function(response) {
console.log("recived data requested");
$scope.databases = response;
});
}
// Call refresh to get req
refresh();
});// Controller
index.html
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="contact in databases">
{{ contact }}
</li>
</ul>
<button type="button" onclick="hitMe()">Click Me!</button>
</div>
</body>