我遇到的问题是我通过页面控制器从后端调用数据库查询,如果函数没有在后端控制器中立即返回,则页面控制器中会出现错误。我不知道哪一方是罪魁祸首:angular或nodejs?
仅供参考,后端路由在我手动输入时有效,如果查询非常小并且几乎立即返回,则页面控制器中的功能成功。
的PageController
*(void **)
资源服务
$scope.getItem = function(item) {
Item.item_query({ itemId: itemId}, function(result) {
console.log("result" + result);
}, function(err) {
console.log("err" + err);
});
};
});
后端控制器
window.app.factory("Item", function ($resource) {
return $resource('api/:action/:itemId',{},
{
get_item_files: {
method: 'GET',
isArray: true,
params: {
action: 'items'
}
},
item_query: {
method: 'GET',
isArray: true,
params: {
action: 'items',
itemId: '@itemId'
},
cache: false
}
});
}
后端路线
exports.getItem = function(req, res) {
var itemId = req.params.itemId;
var query = "SELECT c.name, * FROM (\
SELECT p.champion_id\
, count(p.item0 = ? OR NULL)::int2 AS it0\
, count(p.item1 = ? OR NULL)::int2 AS it1\
, count(p.item2 = ? OR NULL)::int2 AS it2\
, count(p.item3 = ? OR NULL)::int2 AS it3\
, count(p.item4 = ? OR NULL)::int2 AS it4\
, count(p.item5 = ? OR NULL)::int2 AS it5\
FROM matchversion mv\
CROSS JOIN matchtype mt\
JOIN match m USING (matchtype_id, matchversion_id)\
JOIN participant p USING (match_id)\
WHERE mv.matchversion = \'5.14\'\
AND mt.matchtype = \'RANKED_SOLO_5x5\'\
AND p.winner = True\
GROUP BY p.champion_id\
HAVING count(p.item0 = ? OR NULL)::int2 > 0\
OR count(p.item1 = ? OR NULL)::int2 > 0\
OR count(p.item2 = ? OR NULL)::int2 > 0\
OR count(p.item3 = ? OR NULL)::int2 > 0\
OR count(p.item4 = ? OR NULL)::int2 > 0\
OR count(p.item5 = ? OR NULL)::int2 > 0\
) p\
JOIN champion c USING (champion_id)";
var bindings = [itemId, itemId, itemId, itemId, itemId, itemId, itemId,
itemId,itemId,itemId,itemId,itemId]
return pg.raw(query, bindings).then(function(resp) {
return resp.rows;
}).then(function(rows) {
res.jsonp(rows);
}).catch(function(err){
console.log(err);
});
答案 0 :(得分:0)
解决了它。我完全忘记发布的是实际的HTML。单击链接后,我有一个href和ng-click。如果查询持续时间过长,则href接管并取消它。