Hi,

i asked for help earlier and got an answer, but since i have a different 
issue i'm posting a new thread.

I fetch json data in my controller, and i want to show those data in my 
view.

In movie.html i type a movie id in an input, and with ng-change it load the 
getMovie function.

app.factory('tmdb', ['$http', '$q', '$log', function($http, $q, $log) {
  return {
    movie: function(id) {
      var deffered = $q.defer();
      
$http.get('https://api.themoviedb.org/3/movie/'+id+'?api_key=3b21647fbda0a5b52703c04d6e74169e&language=fr').then(function(response)
 
{ //promise
        deffered.resolve(response);
      }, function() {
        deffered.reject('Le film ID ' + id + ' n\'existe pas'); // if movie 
ID doesn't exists
      });
      return deffered.promise;
    }
  };
}]);

app.controller('MovieCtrl', ['$http', '$log', 'tmdb', function($http, $log, 
tmdb){
  this.film = {};
  
  this.getMovie = function(id, variable) {
    tmdb.film(id).then(function(response) {
      variable = response.data;
    });
  };
}]);


movie.html

<div class="row">
<input type="number" ng-model='movieId' ng-change="movie.getMovie(movieId, 
movie)">
<p>ID du film : {{movieId}}</p>
    <div class="col-md-4">
        <img 
ng-src="http://image.tmdb.org/t/p/w500{{movie.film.poster_path}}"; 
width="200" height="300"/>
    </div>
    <div class="col-md-8">
        <a ng-href="#/info/{{movie.film.id}}"><h4 
ng-bind="movie.film.title"></h4></a>
        <div class="row">
            <label class="col-md-2">Année:</label>
            <span class="col-md-8" ng-bind="movie.film.release_date | 
date:'yyyy'"></span>
        </div>
        <div class="row">
            <label class="col-md-2" ng-model="movie.film.vote_average"
>Note:</label>
        </div>
    </div>
</div>



I tried replacing ng-bind with a expression like:

 <h4 ng-bind="movie.film.title"></h4>
by
<h4>{{movie.film.title}}</h4>


but it doesn't work.

I also tried using $scope.$apply() but it says that $digest is already 
called, i'd rather not use $scope if possible thought.

So my question is, how to update the view ?

thanks !

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to