I have an array of a nicknames of twitch streamers. Now I want to call their API to retrieve data about the channel, and append it to the original JSON object in order to work with it on the front-end of my solution.
Now when I console.log the results of the $https call I get results as an object logged to the console, but I can't figure out why it doesn't append it to the original streams array and show it in my html.
Any help is appreciated
my html:
<div ng-app="twitchAPI" ng-controller="streamController">
{{ error }}
<div>
{{ streams }}
</div>
</div>
my app:
var twitchAPI = angular.module('twitchAPI', []);
twitchAPI.controller('streamController', function($scope, $http) {
$scope.streams = [{
'nick': 'freecodecamp'
}, {
'nick': 'storbeck'
}, {
'nick': 'terakilobyte'
}, {
'nick': 'habathcx'
}, {
'nick': 'RobotCaleb'
}, {
'nick': 'thomasballinger'
}, {
'nick': 'noobs2ninjas'
}, {
'nick': 'beohoff'
}, {
'nick': 'brunofin'
}, {
'nick': 'comster404'
}, {
'nick': 'RiotGamesBrazil'
}];
var onInfoReceived = function(response) {
return response.data;
}
var onInfoError = function(reason) {
$scope.error = "Could not fetch the information!"
}
var getStreamInfo = function(nick) {
$http.jsonp('https://api.twitch.tv/kraken/channels/' + nick + '?callback=JSON_CALLBACK')
.then(onInfoReceived, onInfoError);
}
for (var x in $scope.streams) {
$scope.streams[x].nick.channelInfo = getStreamInfo($scope.streams[x].nick);
};
});
I've also created a codepen of the thing, since this is a freeCodeCamp exercise.