【发布时间】:2017-01-21 16:21:17
【问题描述】:
我正在使用 twitch.tv api 并使用 Angular $resource 工厂。我尝试使用的端点是:GET /channels/:channel。我要做的是获取每个数组元素的通道。我试过 /channels/users[1] 但我知道这是错误的。如何获取数组中所有用户的 :channel ?或者有更好的方法吗?
(function() {
angular.module('twitch', ['ngResource'])
.controller('TwitchController', ['$scope', 'TwitchAPI', function($scope, TwitchAPI) {
$scope.getAPI = function(){
var users = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
for(var i = 0; i < 8; i++){
TwitchAPI.get({channel: users.i});
}
}
$scope.online = [];
$scope.offline = [];
}])
.factory('TwitchAPI', function TwitchAPIFactory($resource){
return $resource('https://api.twitch.tv/kraken/channels/:channel', { callback: "JSON_CALLBACK" });
});
})();
【问题讨论】:
标签: javascript angularjs jsonp angular-resource twitch