Skip to content

Instantly share code, notes, and snippets.

@vilmosioo
Last active January 3, 2016 16:49
Show Gist options
  • Save vilmosioo/8491775 to your computer and use it in GitHub Desktop.
Save vilmosioo/8491775 to your computer and use it in GitHub Desktop.
Loading component during route resolve phase
$routeProvider
.when('/about-us', {
title: 'About Us',
templateUrl: 'views/about_us_view.html',
controller: 'AboutUs_controller',
resolve: {
resolvedData: function($q, $timeout){
// create a promise that only gets resolved when all components are loaded
var defer = $q.defer();
// Load and execute scripts. You can use any script loader you prefer. In this example I use $LAB
$LAB.script('scripts/controllers/aboutus_controller.js').wait(function(){
// at this point, aboutus_controller.js was loaded and executed, resolve the promise
$timeout(defer.resolve);
});
// return promise
return defer.promise;
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment