-2

私はつまらないアプリに取り組んでいます。私は$ httpで簡単に行えたかもしれないが、ngresourceで試してみることにした。私が抱えている問題は、オフラインタブです。ユーザーはロゴやユーザー名を表示していません。ストリームの約束がオフラインのユーザーのためにnullを返すので、ロゴ/ユーザー名を取得できないためです。とにかく$ scope.all配列をフィルタリングし、オフラインユーザーをオフラインタブの下に置くことができますか?どんな助けでも大歓迎です!角度のあるソースと異なる約束

​​

.controller('TwitchController', ['$scope','$q', 'TwitchAPIChannel', function($scope, $q, TwitchAPIChannel) { 

    var users = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"]; 
    //var offlineUsers = []; 

    // Create promise for each channel/stream and store both in an empty object 
    var channelPromises= users.reduce(function(map, user) { 
     map[user] = TwitchAPIChannel.Channels.get({channel: user}).$promise; 
     return map; 
    }, Object.create(null)); 

    var streamPromises = users.reduce(function(map, user) { 
     map[user] = TwitchAPIChannel.Streams.get({channel: user}).$promise; 
     return map; 
    }, Object.create(null)); 



    // Calling promises for each channel/stream 
    $q.all(channelPromises).then(function(channels) { 
     $scope.allUsers = []; 
     //pushing all channels to the allUsers array 
     angular.forEach(channels, function(channel) { 
      $scope.allUsers.push(channel); 
     }); 
    }); 

    $q.all(streamPromises).then(function(streams) { 
     $scope.onlineUsers = []; 
     var offlineUsers = []; 
     $scope.offlineUsers = []; 
     angular.forEach(streams, function(stream) { 
     if(stream.stream){ 
      $scope.onlineUsers.push(stream); 
     } else { 
      $scope.offlineUsers.push(stream); 
     } 
     }); 
    }); 

    //tabs 
    this.tab = 1; 
    this.setTab = function (tabId) { 
     this.tab = tabId; 
    }; 
    this.isSet = function (tabId) { 
     return this.tab === tabId; 
    }; 

    }]) 

// Twitch API Factory using $resource 
.factory('TwitchAPIChannel', function TwitchAPIFactory($resource){ 
    return { 
    Channels: $resource('https://api.twitch.tv/kraken/channels/:channel', {}, { 
     get: { 
      method: 'GET', 
      headers: { 
       Accept: 'application/vnd.twitchtv.v3+json', 
       'Client-ID': 'haibznywychj91wl2j76x1v1mx1rgwf' 
      } 
     } 
    }), 
    Streams: $resource('https://api.twitch.tv/kraken/streams/:channel', {}, { 
     get: { 
      method: 'GET', 
      headers: { 
       Accept: 'application/vnd.twitchtv.v3+json', 
       'Client-ID': 'haibznywychj91wl2j76x1v1mx1rgwf' 
      } 
     } 
    }) 
    }; 
}) 
+0

、それはあなたの問題のコードとは何の関係もありません。 – Phil

+0

@Phil私は問題を抱えているコードを改訂して追加しました。 – labanch

答えて

1

あなたのごオフライン]タブでNGクリックは間違っていました。このことから、それを変更します。これに

ng-click="tab = tab==2 ? a : 1" 

を:

ng-click="tab = tab==3 ? a : 3" 

はこちらをご覧ください:http://codepen.io/anon/pen/KgLmjJ?editors=0001問題が何であれ

+0

ありがとう@ウィリアム。それは修正されましたが、オフラインのユーザー名やロゴはまだ表示されません。その部分を修正する方法がわからない。 – labanch

関連する問題