以下问题:我正在运行一个Nodejs服务器和一个mongoDB。到目前为止,我一直以json的形式将查询结果发送到浏览器。
app.get('/gesamtergebnis', function(req,res){
User.aggregate([{$group: {
_id: "$Art",
Anzahl: {$sum: "$Anzahl"}
}
}], function(err,docs){
if(err){console.log(err);}
else {res.json(docs);}
});
});
我的结果是--这些json响应的本质是什么--格式很差。所以我设置了一个带有表格等的html文件。和一个小的ng控制器,用ng重复获取表中的数据,到目前为止没有问题。
function AppCtrl($scope, $http) {
console.log("Hello from AppCtrl")
var showTotal = function(){
$http.get('./gesamtergebnis').success(function(response){
console.log("I got the data I requested!");
$scope.gesamtergebnis = response;
});
}
}
我的路线是:
app.use(express.static(__dirname + "/public")); In the public folder is my index.html
我的问题是: index.html没有收到任何服务器响应;
我需要
没有办法用数据将服务器响应重定向到某个html (也是其他htmls,然后是索引)端点吗?
解决这个问题的最好方法是什么?用角度在客户端完成路由吗?我怎么能轻易做到这一点?
任何帮助都会很好!
胡丘
https://stackoverflow.com/questions/36284207
复制