使用 ng-repeat 显示 mongoose 查询
use ng-repeat to display mongoose queries
我想使用 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>
它只显示 header 你好
这个问题的答案是在控制器中做猫鼬查询,例如:
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[ 中重复它=11=]
我想使用 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>
它只显示 header 你好
这个问题的答案是在控制器中做猫鼬查询,例如:
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[ 中重复它=11=]