在使用ui路由器时在应用配置中设置动态状态
问题描述:
我在角应用中使用ui路由器,我想通过调用操作返回json格式的状态列表,然后在stateProvider中设置状态列表项,从服务器获取ui路由器的状态,可以&其中i做到这一点,这个代码是在App.config中为CONFIG状态:在使用ui路由器时在应用配置中设置动态状态
var list = ?????// how can get state list here?
var populateStates = function() {
angular.forEach(list, function(item) {
$stateProvider.state(item);
};
};
populateStates();
答
简单示例:
var list = [['home', {
url: '/',
templateUrl: '/views/index',
controller: 'HomeCtrl'
}],
['about', {
url: '/about',
templateUrl: '/views/about',
controller: 'AboutCtrl'
}]];
var populateStates = function() {
angular.forEach(list, function(item) {
$stateProvider.state(item[0], item[1]);
};
};