2017-04-11 56 views
0

我得到了youtube API。現在我想在我的網站上顯示我的頻道視頻。 我試過這個,但不起作用。 我的角碼。顯示youtube API v3標題和縮略圖使用Angularjs

var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope,$http) { 
    $http.get("https://www.googleapis.com/youtube/v3/activities?part=snippet,contentDetails&channelId=UC1GU2NAvytA-eWWKUNkA11w&key=MYKEY") 
    .then(function (response) { 
     $scope.videos = response.data; 

     }); 

}); 

我的HTML代碼

<table class="table"> 
       <thead> 
        <tr> 
         <th>Name</th> 

        </tr> 
       </thead> 
       <tbody> 
        <tr ng-repeat="x in videos"> 
        <td>{{ x.title }}</td> 

        </tr> 
       </tbody> 
     </table> 

請告訴我完成工作的方式! 非常感謝!

+0

你會得到任何錯誤?你能分享'videos' json嗎? –

+0

如果您的響應包含密鑰'數據'然後包含密鑰'標題',則您的代碼將起作用。點擊你在代碼中提到的URL,我得到一個錯誤。嘗試輸入有效的網址以使您的代碼正常工作 –

+0

也嘗試'$ scope.videos = response.data.data;'。 –

回答

0

我得到了它 更改角

$scope.videos = response.data;//before 
$scope.videos = response.data.items;//now 

在HTML

<tr ng-repeat="x in videos"> 
     <td>{{ x.snippet.title }}</td> 

    </tr> 

採取了很多的研究做出來。那裏沒有什麼好的教程。他們大多使用jQuery。