如何使用AngularJS从API显示JSON详细信息?

时间:2018-08-23 00:34:47

标签: angularjs

我已经在视图中显示了JSON对象。如何显示一个对象的其他详细信息?

var news= angular.module('news',[]);
news.controller('labController', [
    '$scope', '$http',
    function ($scope, $http) {
        $scope.model={};
        $scope.movies = [];
        //var url = 'https://api.themoviedb.org/3/movie/{movie_id}?api_key=ea12c869f716552bef3493abf72c3617&l&language=en-US'
        var url = 'https://api.themoviedb.org/3/movie/popular?api_key=ea12c869f716552bef3493abf72c3617&language=en-US&page=1';
          $http.get(url)
          .then(function(success){
                $scope.movies = success.data.results;
                $scope.show = false;            
                console.log(success.data.results);
          },function(error){
                console.log(error);
                $scope.show = false;
          });

         function loadDetail(name) {
        var url = 'https://api.themoviedb.org/3/movie/'+name+'?api_key=ea12c869f716552bef3493abf72c3617&language=en-US&page=1&append_to_response=videos,images'
        $http.get(url)
            .then(function (response) {
                $scope.model.detail = response.data.results;
                //console.log(response.data.results);
            }, function (response) {
                $scope.model.detail = { error: true, message: 'Error: ' + response.data.message };
            });
            console.log('cy');    
        }           
}]);

0 个答案:

没有答案