Created
October 22, 2014 13:21
-
-
Save xcarpentier/01f1ce1c85b86f9b60d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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