我正在尝试使用$resource从一个角度执行一个get/query请求到一个指定的路由,这将对一个API进行平分,然后我应该得到一个对象,它的结果来自于API。
这是一个搜索函数。见这一问题的流程:
角度服务:
angular.module('MyApp')
.factory('Search', function($resource) {
return $resource('/api/shows/:_search');
});Ctrl:
$scope.$watch('searchStr', function (tmpStr)
{
if (!tmpStr || tmpStr.length == 0)
return 0;
// if searchStr is still the same..
// go ahead and retrieve the data
if (tmpStr === $scope.searchStr) {
Search.query({'search': $scope.searchStr})
.$promise.then(function(data) {
$scope.responseData = data;
})
}
});查看:
<input type="text" data-ng-model="searchStr">
<textarea> {{responseData}} </textarea>Nodejs:
app.get('api/shows/:search', function(req, res, next) {
console.log(req, res);
request.get('http://thetvdb.com/api/GetSeries.php?seriesname=' + req.params.search, function (error, response, body) {
console.log(error, response, body);
});
});这就是我所需要的,我需要对'api/shows/:search'做一个get请求,并做一些事情来从http://thetvdb.com/api/GetSeries.php?seriesname=' + req.params.search中获得结果,但是我仍然在挣扎着应该如何去做。search param是从角度来的字符串,以到达thetvdb并返回我所需要的。
下面是一个应该返回的示例,以防您用单词"all":http://www.thetvdb.com/api/GetSeries.php?seriesname=all&language=en发送字符串param
有什么建议吗?
发布于 2016-05-20 15:31:46
至少您的nodejs路由必须返回响应中的字符串:
app.get('api/shows/:search', function(req, res, next) {
request.get('http://thetvdb.com/api/GetSeries.php?seriesname=' + req.params.search, function (error, response, body) {
console.log(error, response, body);
res.end(body);
});
});https://stackoverflow.com/questions/37350341
复制相似问题