Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <select ng-model="selectedMovieId" ng-if="movies.length>0" ng-options="movie.id as movie.title for movie in movies track by movie.id"></select>
  2. <div>
  3. {{selectedMovieId||'No movie selected'}}
  4. </div>
  5.  
  6. var app = angular.module("movieApp", []);
  7.  
  8. app.controller("movieCtrl", ["$scope", "$http", function($scope, $http) {
  9. $scope.apiKey = ''
  10. var baseUrl = 'https://api.themoviedb.org/3/'
  11. $scope.movies = []
  12. $scope.searchMovie = function() {
  13. var url = baseUrl + 'search/movie?api_key=' + $scope.apiKey + '&query=' + $scope.queryString;
  14. $http.get(url)
  15. .then(function(response) {
  16. $scope.movies = response.data.results;
  17. }, function() {
  18. console.log("some error");
  19. })
  20. }
  21. $scope.getCredits = function() {
  22. var url = baseUrl + 'movie/' + $scope.selectedMovieId + '/credits?api_key=' + $scope.apiKey
  23. console.log(url)
  24. console.log($scope.movies)
  25. /*$http.get(url)
  26. .then(function(response) {
  27. console.log(response.data)
  28. $scope.actors = response.data.results;
  29. }, function() {
  30. console.log("some error");
  31. })*/
  32. }
  33. }]);
  34.  
  35. <div ng-app="movieApp" ng-controller="movieCtrl">
  36. <input type='text' ng-model='queryString' ng-submit="searchMovie()">
  37. <button ng-click="searchMovie()">
  38. Search
  39. </button>
  40. <hr/>
  41. <select ng-model="selectedMovieId" ng-if="movies.length>0" ng-options="movie.id as movie.title for movie in movies track by movie.id">
  42. </select>
  43. <div>
  44. {{selectedMovieId||'No movie selected'}}
  45. </div>
  46. <button ng-if="movies.length>0" ng-click="getCredits()">
  47. Get Credits
  48. </button>
  49. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement