Persist state when changing to another state

强颜欢笑 提交于 2020-01-06 17:08:54

问题


I want to create dynamic navigation, that i can change navigation item by state, the problem is when i change the content, the navigation is cleared out, i already tried this solution but it seems not working on my cases

Here is my plunker

And here is my state configuration

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:


I would recommend using ui-router-extras and its sticky:true property.



来源:https://stackoverflow.com/questions/29280825/persist-state-when-changing-to-another-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!