DanArg
DanArg

Reputation: 37

Ionic/angular not reading json data from api

I cant see and get the data and its not display

here is the controller code

angular.module("film-module")

.controller("films-controller", function($scope, Film) {

var initView = function(){

    var film1 = Film.build({"Title":"The Martian","Year":"2015","Rated":"PG-13","Released":"02 Oct 2015","Runtime":"144 min","Genre":"Adventure, Drama, Sci-Fi","Director":"Ridley Scott","Writer":"Drew Goddard (screenplay), Andy Weir (book)","Actors":"Matt Damon, Jessica Chastain, Kristen Wiig, Jeff Daniels","Plot":"During a manned mission to Mars, Astronaut Mark Watney is presumed dead after a fierce storm and left behind by his crew. But Watney has survived and finds himself stranded and alone on the hostile planet. With only meager supplies, he must draw upon his ingenuity, wit and spirit to subsist and find a way to signal to Earth that he is alive.","Language":"English, Mandarin","Country":"USA, UK","Awards":"Nominated for 7 Oscars. Another 31 wins & 161 nominations.","Poster":"http://ia.media-imdb.com/images/M/MV5BMTc2MTQ3MDA1Nl5BMl5BanBnXkFtZTgwODA3OTI4NjE@._V1_SX300.jpg","Metascore":"80","imdbRating":"8.1","imdbVotes":"383,169","imdbID":"tt3659388","Type":"movie","Response":"True"});

    var film2 = Film.build({"Title":"Inception","Year":"2010","Rated":"PG-13","Released":"16 Jul 2010","Runtime":"148 min","Genre":"Action, Mystery, Sci-Fi","Director":"Christopher Nolan","Writer":"Christopher Nolan","Actors":"Leonardo DiCaprio, Joseph Gordon-Levitt, Ellen Page, Tom Hardy","Plot":"A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.","Language":"English, Japanese, French","Country":"USA, UK","Awards":"Won 4 Oscars. Another 139 wins & 192 nominations.","Poster":"http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg","Metascore":"74","imdbRating":"8.8","imdbVotes":"1,405,608","imdbID":"tt1375666","Type":"movie","Response":"True"});

            $scope.films = [film1, film2];
    };

    $scope.$on("$ionicView.loaded", function(){

        initView();
    });
});

and the model:

angular.module("film-model", [])

.factory("Film", function() {

    function Film(title,year, runtime, director,actors, plot,poster,imdbRating) {

        this.title = title;
        this.year = year;
        this.runtime = runtime;
        this.director = director;
        this.actors = actors;
        this.plot = plot;
        this.poster = poster;
        this.imdbRating = imdbRating;

    }

    Film.build = function(data){

        if (!data)
        return null;
        return new Film(data.title,data.year,data.runtime, data.director, data.actors, data.plot, data.poster, data.imdbRating);

    }
    Film.prototype.toJson = function(){

        return angular.toJson(this);

    }
    Film.fromJsonBunch = function(data){
        if (angular.isArray(data)){
            return data.map(Film.build).filter(Boolean);
      }    
      return Film.build(data);
    }

    return Film;

})

this is the html:

    <ion-list>
        <ion-item ui-sref="app.films-details" ng-repeat="film in films">{{film.title}}</ion-item>

    </ion-list> 
</ion-content> 

Upvotes: 0

Views: 175

Answers (1)

Sid
Sid

Reputation: 7631

You are using 'Title' as the property while you have defined it as 'title'. JavaScript properties are case sensitive. Try changing that and see if that works.

Upvotes: 0

Related Questions