2013-09-30 57 views
3

我在角應用中使用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(); 

回答

3

簡單示例:

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]); 
    }; 
}; 
相關問題