【问题标题】:set dynamic states in app config when use ui router使用 ui 路由器时在应用程序配置中设置动态状态
【发布时间】:2014-05-17 23:57:03
【问题描述】:

我在 Angular 应用程序中使用 ui 路由器,我想通过调用以 json 格式返回状态列表的操作从服务器获取 ui 路由器的状态,然后在 stateProvider 中设置状态列表项,我如何以及在哪里执行此操作,此代码是在 app.Config 中获取配置状态:

var list = ?????// how can get state list here?

var populateStates = function () {

    angular.forEach(list, function(item) {
       $stateProvider.state(item);
    };
};

populateStates(); 

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    简单示例:

    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]);
        };
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多