Nahid Hasan
Nahid Hasan

Reputation: 707

angular http service not working ...why?

//show movie list 100

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Movie search App</title>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script type="text/javascript" src="controller.js"></script>

</head>
<body ng-app="myApp">

<div ng-controller="movies">

 <ul>
     <h1>IMDB 100 Movies</h1>

     <li ng-repeat="movie in movies">

      {{ movie.title }}



     </li>


 </ul>

    enter code here

</div>

</body>
</html>

//json file

{
    "records":

[

  {
        "title": "The Shawshank Redemption",
        "rank": "1",
        "id": "tt0111161"
    },
    {
        "title": "The Godfather",
        "rank": "2",
        "id": "tt0068646"
    },

// controller.js

var app=angular.module('myApp',[]);

app.controller('movies', function ($scope,$http) {

    $http.get('localhost/SPA/movies.json');

    .success(function(responce))

    {

         $scope.movies=responce.records; 

    }

});

Upvotes: 1

Views: 587

Answers (2)

Majid Parvin
Majid Parvin

Reputation: 4992

Change your controller.js to:

var app=angular.module('myApp',[]);

app.controller('movies', function ($scope,$http) {
    $http.get('localhost/SPA/movies.json').success(function(responce) {
         $scope.movies=responce.records; 
    });

Upvotes: 0

quirimmo
quirimmo

Reputation: 9988

Remove ; from this line:

$http.get('localhost/SPA/movies.json');

Upvotes: 3

Related Questions