$resource
を使用してAngularからget/query要求を行い、APIにpingを実行する指定されたルートにアクセスしようとしています。その結果、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'
へのリクエストをして、http://thetvdb.com/api/GetSeries.php?seriesname=' + req.params.search
の結果を得るために何かをする必要がありますが、どうやってそれをやるべきかにはまだ苦労しています。 search
paramは、thetvdb
に行き、必要なものを返すために、Angularから来る文字列です。 http://www.thetvdb.com/api/GetSeries.php?seriesname=all&language=en
任意の提案:ここ
は、それはあなたが単語「すべて」と文字列のparamを送信した場合のリターンがどうあるべきかの例ですか?
は 'req.params.search'は値が含まれていますか? – chresse
@chresse理由は分かりませんが、Nodejsでconsole.logを実行しようとしていますが、端末に何も表示されません。 – TheUnnamed
@chresse私はちょうど 'すべての単語を送信し、私は端末で見るすべてこれです:GET/api/shows?search = all 200 109.559 ms - 2806780 – TheUnnamed