I am developing a simple MEAN stack application. I am using angular routing to redirect to a page based on the Id of the item clicked like this:
when('/story/:id', {
template: '<news-detail></news-detail>'
})
When an item is clicked it should go to a page like this : http://localhost:3002/story/58fbcf765865db1d8da94b41
but on that page I get a "Cannot GET /story/58fbcf765865db1d8da94b41" node error.
from back end I have tried this:
app.get('/story/:id', function(req, res){
if(req){
var id = req.params.id;
PostProfile.News.findById(id, function(err, item){
if(item){
console.log("found")
res.send(item)
}
})
}
})
This solution just displays some raw json on the page
{"_id":"58fbc2834f675c1cdb7dc628","title": .....
What is the walk around for this and how can I use angular to make the request by id without going through nodejs first.
thanks alot.
via charles okojie
No comments:
Post a Comment