2016-04-04 34 views
0

gelen json verilerini okuma değil açısal benİyonik/API

görmek ve veri almak ve onun ("film modülü") burada

kontrolör kodunu

angular.module olduğunu göstermez olamaz .controller ("filmleri kontrol cihazı", işlevi ($ kapsamı, 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/[email protected]_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/[email protected]@._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(); 
    }); 
}); 

ve model:

:angular.module ("film model" [])

.factory ("film", fonksiyon() {

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; 

})

bu html

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

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

+0

Başlangıçta initView() 'i çağırıyorsunuz? Şüphesiz, initView() 'ın içinden ... ... eklediğiniz dinleyici değil. – Antiga

+0

@Antiga Ben girinti berbat düşünüyorum ama $ scope.on initView – Sid

+0

@Sid, ah, yeterince adil olduğunu. – Antiga

cevap

0

'Başlık' olarak tanımladığınız sırada, 'Başlık' özelliğini kullanıyorsunuz. JavaScript özellikleri büyük/küçük harfe duyarlıdır. Bunu değiştirmeyi deneyin ve işe yarayıp yaramadığını görün.

+0

harika! Orada değişmeyi denemedim, teşekkürler! – DanArg