Skip to content

Instantly share code, notes, and snippets.

@xcarpentier
Created October 22, 2014 13:21
Show Gist options
  • Save xcarpentier/01f1ce1c85b86f9b60d3 to your computer and use it in GitHub Desktop.
Save xcarpentier/01f1ce1c85b86f9b60d3 to your computer and use it in GitHub Desktop.
/* A éviter */
angular
.module('app')
.controller('Avengers', Avengers);
function Avengers (movieService) {
var vm = this;
// unresolved
vm.movies;
// resolved asynchronously
movieService.getMovies().then(function (response) {
vm.movies = response.movies;
});
}
/* Recommandé */
// route-config.js
angular
.module('app')
.config(config);
function config ($routeProvider) {
$routeProvider
.when('/avengers', {
templateUrl: 'avengers.html',
controller: 'Avengers',
controllerAs: 'vm',
resolve: {
moviesPrepService: function (movieService) {
return movieService.getMovies();
}
}
});
}
// avengers.js
angular
.module('app')
.controller('Avengers', Avengers);
function Avengers (moviesPrepService) {
var vm = this;
vm.movies = moviesPrepService.movies;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment