我在这里尝试使用“_id”将两个页面链接在一起,并将其保存在url中。但是当我点击角度href链接在nodejs中链接时,我正在重新加载我的页面。这是我的代码 angularJs
<a style="text-decoration:none;" href="/ordercustomer/{{x._id}}"> {{ x.orders.length || 0 }} order </a>
节点js
app.get('/ordercustomer/:id', function(req, res, next){
console.log(req.params.id);
console.log('I received another get request');
dbConn.then(function(db) {
var dd = db.db("customermanagement");
dd.collection('customers').findOne({_id:ObjectId(req.params.id)},function(err, results) {
console.log(results);
res.redirect('/index1.html#!/ordercustomer/'+req.params.id)
});
});
});
其中index.html是角度路由中的主页面。 app.js
when('/ordercustomer/:userid1', {
templateUrl: 'ordercustomer.html',
controller: 'ordercustomerCtrl'
}).
答案 0 :(得分:0)
您的节点获取api将是:
app.get('/ordercustomer/:id', function(req, res, next){
dbConn.then(function(db) {
var dd = db.db("customermanagement");
dd.collection('customers').findOne({_id:ObjectId(req.params.id)},
function(err, results) {
res.status(200).send({ status: 1000 }); //and other json fileds whatever you want to send back to client
});
});
});
在你的角度客户端控制器中:
$scope.yourSubmitFunction = function(id){
$http({
url : '/ordercustomer/' + id,
method: 'GET'
}).then(function(result){
//this is your result from node api
if(result.status === 1000){
//use $window or $location for redirection to your page
}
})
};