Angularjs无法获取/显示数据

时间:2014-09-14 12:14:18

标签: javascript angularjs

有点坚持一个问题所以我有一个控制器看起来像:

'use strict';
angular.module('Movie.services', []).service('Movie', ['$q', '$http', function($q, $http) {

/* global config*/  
var API_URL = '';
var API_KEY = 'xxx';

var movieService = {

    findCast : function( id ) {

        var id = id; // get person id
        var cast = [];

        var promise = $http.get(API_URL + id, {         
            params: {
                api_key: API_KEY 
            }}).then(function(result) {

            angular.forEach(result, function(item) {
                cast.push(item);
                console.log(item);
            });
             return cast;
        });
        return promise;
    },
    getMovies : function(){

    },
  }
  return movieService;
}]);

它返回整个对象,很好。 Screen

现在我被困在要解析的部分是在我的main.js中得到的:

Movie.findCast(person_id).then(function(result){
    $scope.getCast = result;
    console.log($scope.getCast);
});

在我的HTML中,我可以{{getCast}},我将获得整个JSON:

[{"adult":false,"also_known_as":[],"biography":"Seth Rogen (born April 15, 1982) is a Canadian actor, comedian, voice artist, screenwriter, and film producer. Rogen began his career doing stand-up comedy for four years during his teens, coming in second place in the Vancouver Amateur Comedy Contest in 1998. While still living in his native Vancouver, he landed a supporting role in Freaks and Geeks. Shortly after Rogen moved to Los Angeles for his role, Freaks and Geeks was canceled after one season due to poor ratings. He then got a part on the equally short-lived Undeclared, which also hired him as a staff writer.\nAfter landing a job as a staff writer on the final season of Da Ali G Show, for which Rogen and the other writers received an Emmy nomination, he was guided by film producer Judd Apatow toward a film career. Rogen was cast in a major supporting role and credited as a co-producer in Apatow's directorial debut, The 40-Year-Old Virgin. \n\nAfter receiving critical praise for that performance, Universal Pictures agreed to cast him as the lead in Apatow's next directorial feature, Knocked Up.\n\nRogen has appeared in the films Donnie Darko, You, Me and Dupree, Zack and Miri Make a Porno, Observe and Report, and The Green Hornet, and also in the Apatow-produced comedies The 40-Year-Old Virgin, Knocked Up, Superbad, Pineapple Express, and Funny People. He and his comedy partner Evan Goldberg co-wrote the comedy films Superbad and Pineapple Express, for which he originally intended to headline while in high school. Rogen has provided voice talents in the animated films Horton Hears a Who!, Kung Fu Panda, and Monsters vs. Aliens. He also supports Crowdrise, a charitable networking site.","birthday":"1982-04-15","deathday":"","homepage":"http://www.seth-rogen.com/","id":19274,"imdb_id":"nm0736622","name":"Seth Rogen","place_of_birth":"Vancouver, British Columbia, Canada","popularity":14.8509727429298,"profile_path":"/3U9s4dvXQuk1l3ZT3MqwqpmeRqI.jpg"},200,null,{"method":"GET","transformRequest":[null],"transformResponse":[null],"params":{"api_key":"0df011bca7e5171f5bea292e818ace29"},"url":"http://api.themoviedb.org/3/person/19274","headers":{"Accept":"application/json, text/plain, */*"}},"OK"]

但是一旦我尝试{{getCast.biography}},它就会给我一些未定义的内容。

我如何解析数据?

1 个答案:

答案 0 :(得分:0)

那是因为它不是getCast.biography而是getCast[0].biography