Angularjs - Error With Themoviedb's Api
So, currently i'm working on a web-app using theMovieDB's API, and it's an AngularJS application. I just need to get all popular films, but it doesn't seems to work .. Here is my c
Solution 1:
The correct MovieDB API (version 3) endpoint is http://api.themoviedb.org/3
. When using JSONP you should provide a callback. Below is working code snippet for you.
It's quite elaborate for example's sake.
JavaScript
var app = angular.module('plunker', []);
app.controller('MyCtrl', function($scope, $http) {
var base = 'http://api.themoviedb.org/3';
var service = '/movie/popular';
var apiKey = 'just_copy_paste_your_key_here';
var callback = 'JSON_CALLBACK'; // provided by angular.jsvar url = base + service + '?api_key=' + apiKey + '&callback=' + callback;
$scope.result = 'requesting...';
$http.jsonp(url).then(function(data, status) {
$scope.result = JSON.stringify(data);
},function(data, status) {
$scope.result = JSON.stringify(data);
});
});
Template
<bodyng-controller="MyCtrl"><h3>MovieDB</h3><pre>{{ result }}</pre></body>
Result would be something like
Related plunker here http://plnkr.co/edit/gwB60A
Post a Comment for "Angularjs - Error With Themoviedb's Api"