價值正如我在我的標題提到,當我使用的UI路由器發送一個參數去的URL,並嘗試使用express.get(URL)我得到:param名稱而不是它的值。Express.get越來越變量名,而不是它是從AngularJS UI路由器
這裏是我的代碼:
AngularJS UI路由器狀態:
.state('post', {
url: '/blog/:postID',
templateUrl: 'app/views/post.html',
controller: 'PostCtrl'
})
AngularJS HTTP請求
$http.get('/blog/:postID').success(function(data) {
console.log(data);
$scope.singlePost = data;
}).catch(function(error) {
console.log(err);
});
HTML界面路由器網址
<h1><a ui-sref="post({ postID: post._id })">{{ post.title }}</a></h1>
快遞。 get()方法
app.get('/blog/:id', function(req, res) {
Post.findById(req.params.id, function(err, singlePost){
console.log(singlePost);
if (err) {
console.log(err);
} else {
res.json(singlePost);
}
});
});
我得到以下錯誤控制檯
{ [CastError: Cast to ObjectId failed for value ":postID" at path "_id"]
message: 'Cast to ObjectId failed for value ":postID" at path "_id"',
name: 'CastError',
kind: 'ObjectId',
value: ':postID',
path: '_id',
reason: undefined }
爲什麼發生的新手將不勝感激的任何幫助和/或解釋。 謝謝。
你必須從您的角度JS應用到節點服務器的HTTP請求。我在這裏沒有看到。 – Mani
是啊,我忘了補充它。我的錯。增加了它 –
我很驚訝地看到你的http請求針對/博客。 – Mani