Skip to content

Instantly share code, notes, and snippets.

@Hendrixer
Created June 15, 2015 19:18
Show Gist options
  • Save Hendrixer/50d2bcfbcce98619147f to your computer and use it in GitHub Desktop.
Save Hendrixer/50d2bcfbcce98619147f to your computer and use it in GitHub Desktop.
using resolve with components ng
angular.module('app', ['ui.router'])
.config(function($stateProvider){
$stateProvider
.state('app', {
url: '/app',
resolve: {
// DataService must be a valid dependecny somewhere
// user any valid service
// data will be the name of the resolved value
data: function(DataService /*, $http, $log, */){
// promise returning function
return DataService.getData();
}
},
// inject data
controller: function(data, $scope){
// bind to scope or this
// if this, use controllerAs
$scope.data = data.
},
template: '<my-component the-data="data"></my-component>'
});
})
.directive('myComponent', function(){
return {
scope: {
'theData': '='
}
// ... the rest
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment