Created
June 15, 2015 19:18
-
-
Save Hendrixer/50d2bcfbcce98619147f to your computer and use it in GitHub Desktop.
using resolve with components ng
This file contains 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
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