我的网站上的用户可以搜索movietitle,然后下拉列表将显示所有相应的标题。然后他们可以点击一个标题将该电影添加到他们的监视列表中。TypeError:无法读取undefined的属性'original_title'
当他们点击一个标题addMovie
函数下面的触发器。
$scope.addMovie = function() {
'http://api.themoviedb.org/3/movie/206647?api_key=a8f7039633f2065942cd8a28d7cadad4&append_to_response=releases'
// Search for release dates using the ID.
var base = 'http://api.themoviedb.org/3/movie/';
var movieID = $(event.currentTarget).parent().find('.movieID').text()
var apiKey = 'a8f7039633f2065942cd8a28d7cadad4&query='
var append_to_response = '&append_to_response=releases'
var callback = 'JSON_CALLBACK'; // provided by angular.js
var url = base + movieID + '?api_key=' + apiKey + append_to_response + '&callback=' + callback;
$http.jsonp(url,{ cache: true}).
success(function (data, status, headers, config) {
if (status == 200) {
// $scope.movieListID = data.results;
$scope.movieListID = data;
console.log($scope.movieListID)
} else {
console.error('Error happened while getting the movie list.')
}
}).
error(function (data, status, headers, config) {
console.error('Error happened while getting the movie list.')
});
createMovie.create({
title: $scope.movieListID.original_title
}).then(init);
};
HTTP请求的工作并在控制台中我能找到对象和original_title
但create方法失败。
TypeError: Cannot read property 'original_title' of undefined at Scope.$scope.addMovie
所以我猜title: $scope.movieListID.original_title
没有直接保存JSON数据的正确方法是什么?
谢谢,我认为'MovieListID'可以访问该控制器中的所有内容。 –