Hope you have had a chance to look into my last tutorial which talks about the technology stack and creating the UI html page with module and controller, Event Binding with UI elements, and Routing in Angular JS with partial templates. Kindly find the links here:
- AngularJS And ASP.NET MVC Movie Library Application - Part One
- AngularJS And ASP.NET MVC Movie Library Application - Part Two
- AngularJS And ASP.NET MVC Movie Library Application- EventBinding with UI Elements - Part Three
- AngularJS And ASP.NET MVC Movie Library Application - AngularJS Routing with partial templates - Part Four
Moving ahead, in this article, we’ll focus on the integration of live movie API within an existing application.
Kindly open the given URL and register yourself. After registering, you will get a token which we’ll be using in this article to retrieve the information/data from API.
http://api.myapifilms.com/imdb
Once you register yourself, you should receive an email like the given image, with some token value.

Open the website with the link, shared above, and fill in the details, as shown below in the following images.


As soon as you click on the submit button, you should receive a response in JSON format, as given below:

You may also get XML response for just making amendments either in request or in format dropdown, as shown below:

So far so good. We are now able to use this API URL within our application.
Open you solution and find routing.js file to add a new Controller into this, as give below:

- routingApp.controller("ApiMovieController", ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
- $scope.SearchMovieByTitle = function () {
- var title = $scope.searchByTitle;
- alert(title);
- $http.jsonp("http://api.myapifilms.com/imdb/idIMDB?title=" + title + "&token=5bf98789787hghjg4&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&filter=2&exactFilter=0&limit=5&forceYear=0&trailers=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0&adultSearch=0&goofs=0"es=0&fullSize=0&companyCredits=0&callback=JSON_CALLBACK").success(function (response) {
- console.log(response);
- $scope.movies = response.data.movies;
- })
- }]);
Note: If you have noticed, in the above code segment, you have injected a dependency $http and $timeout. For now, only concentrate on the $http and forget about $timeout.

Complete code for routing.js main JavaScript file is shown below:
Code Routing.js file
- /// <reference path="../Scripts/angular.js" />
- /// <reference path="../Scripts/fusioncharts.js" />
- /// <reference path="../Scripts/fusioncharts.charts.js" />
- /// <reference path="DataService.js" />
- /// <reference path="../Scripts/angular-route.js" />
- var routingApp = angular.module('routingApp', ['ngRoute']);
- routingApp.directive("login", function () {
- var directive = {};
- //restrict = E, signifies that directive is Element directive
- directive.restrict = 'E';
- //template replaces the complete element with its text.
- directive.templateUrl = "/Application/Login.html";//"My first directive";
- return directive;
- });
- routingApp.config(['$routeProvider', function ($routeProvider) {
- //alert("Route Initiated");
- $routeProvider.
- // when('/Home', { templateUrl: '/Application/login.html', controller: 'DotnetPiperController' }).
- when('/Movie', { templateUrl: '/Application/Movie.html', controller: 'MovieController' }).
- when('/SearchMovie', { templateUrl: '/Application/SearchMovie.html', controller: 'ApiMovieController' }).
- when('/Tolly', { templateUrl: '/Application/Tollywood.html', controller: 'tollyController' }).
- otherwise({ redirectTo: '' });
- }]);
- routingApp.controller("tollyController", function ($scope) {
- $scope.tollyMessage = "Welcome to TollyWood to watch Action,Thriller and Suspence movies";
- });
- routingApp.controller("MovieController", ['$scope', function ($scope) {
- $scope.edit = false;
- $scope.message = "Welcome to DotnetPiper.com to learn Angular";
- $scope.error = false;
- $scope.clear = false;
- $scope.success = false;
- // alert("Servcie Called");
- var movies = [
- { title: "Revenent", year: "2015", rating: "5Star", plot: " A revenger Journey" },
- { title: "Counjouring2", year: "2016", rating: "4Star", plot: " A Complete Hourror" },
- { title: "DDLJ", year: "1995", rating: "SuperStar", plot: "Romantic love story" },
- { title: "Sultan", year: "2016", rating: "5Star", plot: "A Warrior" },
- { title: "BajiRao Mastani", year: "2015", rating: "4.5 Star", plot: "Film of the Year" }
- ];
- $scope.movies = movies;
- $scope.AddMovie = function (movie) {
- if ($scope.edit == true) {
- var index = $scope.movies.indexOf(movie);
- // alert("edit Called");
- $scope.movies[index] = movie;
- //alert(movie.rating);
- $scope.updatedMovie = movie;
- $scope.success = true;
- $scope.movie = {};
- }
- else {
- var newMovie = {
- title: $scope.movie.title,
- year: $scope.movie.year,
- rating: $scope.movie.rating,
- plot: $scope.movie.plot
- };
- movies.push(newMovie);
- // alert("Add Called");
- }
- }
- $scope.DeleteMovie = function (movie, index) {
- movies.splice(index, 1);
- // $scope.movie = movie;
- $scope.updatedMovie = movie;
- $scope.success = false;
- $scope.clear = true;
- $scope.movie = {};
- console.log(index);
- }
- $scope.EditMovie = function (movie, index) {
- $scope.selectedRow = null; // initialize our variable to null
- $scope.selectedRow = index;
- $scope.movie = movie;
- $scope.edit = true;
- }
- }]);
- routingApp.controller("ApiMovieController", ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
- $scope.SearchMovieByTitle = function () {
- var title = $scope.searchByTitle;
- alert(title);
- $http.jsonp("http://api.myapifilms.com/imdb/idIMDB?title=" + title + "&token=5bf5tr54-793f-4a6f-91d0-s89t59d45321&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&filter=2&exactFilter=0&limit=5&forceYear=0&trailers=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0&adultSearch=0&goofs=0"es=0&fullSize=0&companyCredits=0&callback=JSON_CALLBACK").success(function (response) {
- console.log(response);
- $scope.movies = response.data.movies;
- })
- }
- $scope.dateTime = new Date().getMinutes();
- // alert($scope.dateTime);
- document.getElementById("btnSearch").addEventListener('click', function SearchMovieByTitleDigest() {
- var title = $scope.searchByTitle;
- $scope.$watch("searchByTitle", function (newValue, oldValue) {
- $scope.searchByTitle = newValue;
- console.log("$scope.searchByTitle Called " + $scope.searchByTitle);
- alert($scope.searchByTitle);
- });
- //console.log(title);
- //alert(title);
- $http.jsonp("http://api.myapifilms.com/imdb/idIMDB?title=" + $scope.searchByTitle + "&token=5bf5tr54-203f-4a6f-91d0-s89t59d45321&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&filter=2&exactFilter=0&limit=5&forceYear=0&trailers=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0&adultSearch=0&goofs=0"es=0&fullSize=0&companyCredits=0&callback=JSON_CALLBACK")
- .success(function (response) {
- $scope.movies = response.data.movies;
- $timeout(function () {
- $scope.$digest();
- }, 100);
- })
- });
- //document.getElementById("btnSearch").addEventListener('click', function () {
- // console.log("Seach Started");
- // alert("Seach Started");
- // $scope.dateTime = new Date().getMinutes();
- // $scope.$digest();
- // });
- }]);
Kindly open your solution and add searchMovie.html file, as shown below in the screenshot:

Please copy and paste the following code in searchMovie.html partial template.
Code for searchMovie.html file,
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <h2>Seach Movie Using IMDB API</h2>
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- <style>
- .selected
- {
- background-color: lightyellow;
- color: red;
- font-weight: bold;
- }
- </style>
- </head>
- <body ng-app="routingApp" class="jumbotron">
- <div ng-controller="ApiMovieController" class="container">
- <!--<div ng-show="success" class="alert-success">Record has been upddated for movie : {{updatedMovie.title}}</div>
- <div ng-show="clear" class="alert-success">Record has been deleted for movie : {{updatedMovie.title}}</div>-->
- <div class="row col-md-8">
- <table class="table table-striped ">
- <tr>
- <td>
- <input type="text" ng-model="searchByTitle" class="form-control" style="width: 300px;" />
- </td>
- {{dateTime}}
- <td>
- <button type="button" ng-click="SearchMovieByTitle()" class="btn btn-info">Search using Angular Scope
- <span class="glyphicon glyphicon-search"></span>
- </button>
- <br />
- </td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="button" id="btnSearch" class="btn btn-info">Seacrh Movie Using EventListener
- <span class="glyphicon glyphicon-search"></span>
- </button>
- </td>
- </tr>
- <tr class="thead-inverse">
- <td style="background-color: Highlight">Title</td>
- <td style="background-color: Highlight">Year of Release</td>
- <td style="background-color: Highlight">Rating</td>
- <td style="background-color: Highlight">Plot</td>
- <td style="background-color: Highlight">Actions</td>
- </tr>
- <tbody>
- <tr ng-repeat="movie in movies" ng-class="{'selected':$index == selectedRow}">
- <td>{{movie.title}}
- </td>
- <td>{{movie.year}}
- </td>
- <td>{{movie.rating}}
- </td>
- <td>{{movie.plot }}
- </td>
- <td></td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </body>
- </html>
Note: Ensure that you had implemented the routing, as shown in the below URL,
The output will be, as depicted below:

Mapping of the above textbox search, using Angular Scope. Whatever value we put into the textbox, ApiMovieController reads that value using scope and passes into http request as Title, as depicted in the screenshot below:

Now, search for the movie as I’ve done for The Revenant and Sultan, both.


Kindly refer tothe given screen for full fledged movie search operation.

Hope it’ll help you some day. Enjoy Coding.

Ravi KandelPosted Aug 14, 2016, 3:04 AM
Awesome
Bhavik PatelPosted Aug 2, 2016, 10:54 PM
Nice
Joginder BangerPosted Aug 2, 2016, 4:20 AM
Good one
Tarun DPosted Aug 2, 2016, 3:03 AM
Thanks for sharing..
Humayun Kabir MamunPosted Aug 1, 2016, 12:28 AM
Nice...
Bhavik PatelPosted Jul 31, 2016, 11:29 PM
Nicely explained
Vignesh ManiPosted Jul 30, 2016, 8:11 PM
Good one
Bikesh SrivastavaPosted Jul 30, 2016, 3:10 PM
Nice one