改变到另一个状态时保持状态 [英] Persist state when changing to another state

查看:28
本文介绍了改变到另一个状态时保持状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建动态导航,我可以按状态更改导航项,问题是当我更改内容时,导航被清除,我已经尝试过了解决方案但它似乎不适用于我的案例

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

这是我的 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');
});

推荐答案

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

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

这篇关于改变到另一个状态时保持状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆