天天看點

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 $stateProvider 連結清單循環追加實作參數化若有疑問,請發表評論或添加微信為你解答: