我想使用angular来显示我从mongoose.find()获得的数组。我的方法
控制器:
requests:function(req,res){
corporate.find({request:false},function(err,corp){
if(corp){
console.log("yes");
res.render('requests',{corp});
}
});
查看:
<!DOCTYPE html>
<html lang="eng" ng-app = "">
<head>
<meta charset = "UTF-8">
<title>Business Requests</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<h1>hello</h1>
<div ng-init = <%="bus=corp"%>>
<p ng-repeat = "c in bus">
Name: {{c.name}} <br>
Email: {{c.email}}<br>
type: {{c.type}}<br>
</p>
</div>
</body>
</html>
除了标题你好之外,它几乎没有显示任何内容
答案 0 :(得分:1)
这个问题的答案是在控制器中进行mongoose查询,例如:
request: function(req,res){
corporate.find({request:true},function(corp){
if(corp){
res.json({success: true, corporate: corp});
}else{
res.json({success: false});
}
}
}
然后使用$ http.get()从json成功的回调中获取查询,并将该值放入范围并在html中重复它