【发布时间】:2016-02-03 19:54:24
【问题描述】:
我在 Express 中获取 URL 参数时遇到问题。 在客户端(Angular)上,我定义状态(ui.router)并发送带有新状态的 URL(id):
.state('home.detail', {
url: '/:id',
templateUrl: 'views/detail.html',
controller: 'DetailController'
});
在后端,我正在尝试获取此 URL(id)
app.get('/api/:id', function(req,res){
var id = req.query.id;
console.log(id);
var queryString = "SELECT * FROM `table` WHERE table.ID=id";
//add to a callback
connection.query(queryString, function (error, results) {
if(error) {
throw error;
}
else {
// send JSON object to the client
res.end(JSON.stringify(results));
//console.log(res);
}
});
});
但我得到了 undefinedid 的值 (console.log(id))。
我做错了什么?
【问题讨论】:
-
如果我的回答解决了您的问题,请告诉我:)
标签: angularjs node.js express angular-ui-router