AngularJs $stateProvider 链表循环追加实现参数化

Lib: https://github.com/angular-ui/ui-router

 

使用实例:

// Some state name examples

// stateName can be a single top-level name (must be unique).
$stateProvider.state("home", {});

// Or it can be a nested state name. This state is a child of the 
// above "home" state.
$stateProvider.state("home.newest", {});

// Nest states as deeply as needed.
$stateProvider.state("home.newest.abc.xyz.inception", {});

// state() returns $stateProvider, so you can chain state declarations.
$stateProvider
  .state("home", {})
  .state("about", {})
  .state("contacts", {});
 

 

 

参数化配置:

var urls = ['news-1' ,'news-2', 'news-3'];

      angular.forEach(urls, function(v) {
        $stateProvider
          .state(v, {
            url: '/' + v,
            views: {
              'aboutBody': { templateUrl: templateBasePath + v }
            }
          });
      });

 

你可能感兴趣的:(每天进步一点点,学习永无止境,AngularJS,纵观千象)