Sunday, 29 September 2013

use $http service in app config when use ui router

use $http service in app config when use ui router

i use angular ui router and coach potato in project, i want ui router
states load from server side and add to state provider in angular
app.Config, but can not inject $http service into app.Config function, my
code like this :
var app = angular.module('app', [ 'ui.router.compat']);
app.config(['$stateProvider', '$routeProvider', '$urlRouterProvider',
'$http',
function ($stateProvider, $routeProvider, $urlRouterProvider, $http) {
$urlRouterProvider
.when('/c?id', '/contacts/:id')
.otherwise('/');
$routeProvider
.when('/user/:id', {
redirectTo: '/contacts/:id'
});
var get = $http.get('/api/Values/');
get.success(function (data) {
list = data.result;
});
var populateStates = function () {
angular.forEach(list, function(item) {
$stateProvider.state(item);
angular.forEach(item.subMenus, function(sub) {
$stateProvider.state(sub);
});
});
};
populateStates();
}]);
how can get data(states) from server in app.Config

No comments:

Post a Comment