换到另一个州时保持状态

时间:2015-03-26 14:18:27

标签: javascript angularjs angular-ui-router

我想创建动态导航,我可以按状态更改导航项,问题是当我更改内容时,导航被清除,我已经尝试过这个 solution 但它似乎不适合我的案件

这是我的plunker

这是我的状态配置

var app = angular.module('knax', ['ui.router', 'ui.bootstrap']);

app.config(
  function($stateProvider) {

    $stateProvider.state('app', {
      views: {
        '@': {
          templateUrl: 'layout.html'
        },
        'navigation-layout@app': {
          templateUrl: 'navigation-layout.html'
        },
        'content-layout@app': {
          templateUrl: 'content-layout.html'
        }

      }
    })
    .state('app.navigation-user', {
      views: {
        'navigation': {
          templateUrl: 'navigation-user.html'
        }
      }
    })
    .state('app.navigation-guest', {
      views: {
        'navigation': {
          templateUrl: 'navigation-guest.html'
        }
      }
    })
    .state('app.content', {
      url: '/content',
      views: {
        'content': {
          templateUrl: 'content.html'
        }
      }
    })
    .state('app.content2', {
      url: '/content2',
      views: {
        'content': {
          templateUrl: 'content2.html'
        }
      }
    });
  }
);

app.run(function($state){
  $state.go('app.navigation-user');
});

1 个答案:

答案 0 :(得分:1)

我建议使用ui-router-extras及其sticky:true属性。

相关问题