How to run a function when another function is complete?
<p>I have a Angular function:</p>

<pre><code>$scope.addMovie = function(movie){
  addMovieRecord(movie)
  addMovieCredits(movie)
}
</code></pre>

<p>And two Javascript functions:</p>

<pre><code>var addMovieRecord = function (movie){

  createMovie.create({
    id:             $scope.movieListID.id,
    release_date:   releaseNL.release_date,
    imdb_rating:    $scope.movieImdbRating.imdbRating,
    title:          $scope.movieListID.original_title,
    image:          $scope.movieListID.poster_path,
    movie_id:       $scope.movieListID.id,
    backdrop:       $scope.movieListID.backdrop_path,
    overview:       $scope.movieCredits.overview
  })

}
</code></pre>

<p>And</p>

<pre><code>var addMovieCredits = function (movie){

  movieService.loadMovies().then(function(response) {
  $scope.moviesCheck = response.data;

}
</code></pre>

<p>So when I run the <code>$scope.addMovie</code> function it should first fire the <code>addMovieRecord</code> function which creates a movie record. Then the <code>createMovie</code> should fire the <code>addMovieCredits</code> to load all the records.</p>

<p>But that doesn't happen. <code>addMovieCredits</code> returns all the records, except the one that just has been created. So it looks like the order isn't correct,</p>

<p>If I fire the <code>addMovieCredits (movie)</code> directly after the create function it does load all the records,</p>

<pre><code>createMovie.create({
  id:             $scope.movieListID.id,
  release_date:   releaseNL.release_date,
  imdb_rating:    $scope.movieImdbRating.imdbRating,
  title:          $scope.movieListID.original_title,
  image:          $scope.movieListID.poster_path,
  movie_id:       $scope.movieListID.id,
  backdrop:       $scope.movieListID.backdrop_path,
  overview:       $scope.movieCredits.overview
}).then(addMovieCredits(movie));
</code></pre>

<p>But that's not what I want. I want to load the movie records after the add function has been completed.</p>

<p>Any suggestions on how to do this?</p>

<p><strong>* update *</strong></p>

<p>This is the createMovie service,</p>

<pre><code>app.factory('createMovie', ['$http', function($http){
  return{
    create: function(movie){
      return $http.post('/movies.json', movie);
    }
  };
}]);
</code></pre>