angularjs - 刷新子状态视图原因丢失的数据从父状态 [英] angularjs - refreshing child state view cause lose of data from the parent state

查看:218
本文介绍了angularjs - 刷新子状态视图原因丢失的数据从父状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的用户界面路由器的状态。

I have the following ui-router states.

.state('admin.userView', {
  abstract:true,
  url:'/user/:id/',
  templateUrl:'./views/user/view.html',
  controller:'userViewController'
})

.state('admin.userView.home', {
  url:'',
  templateUrl:'./views/user/home.html',
  controller:'userHomeController'
})

我必须使用HTTP资源在userViewController至$ scope.users获取用户详细信息。
当我移动到admin.userView.home状态,我可以访问$ scope.users。
但是,当我刷新页面,孩子的状态,在$ scope.users值丢失。
我怎样才能得到相同的。

I have fetched user details using http resource in userViewController to $scope.users. When i move to the admin.userView.home state, I can access the $scope.users . But when i refresh page with child state, the value in the $scope.users is lost. How can i get the same.

推荐答案

尝试将数据移动到 admin.userView 国家申报的决心财产。由于您使用嵌套议决在这里你可以再注入该解决数据到 admin.userView.home 状态声明。下面是从UI路由器文件的摘录。

Try moving that data into the resolve property of the admin.userView state declaration. Since you're using nested resolves here you can then inject that resolved data into the admin.userView.home state declaration. Here's an excerpt from the ui-router documentation.

$stateProvider.state('parent', {
      resolve:{
         resA:  function(){
            return {'value': 'A'};
         }
      },
      controller: function($scope, resA){
          $scope.resA = resA.value;
      }
   })
   .state('parent.child', {
      resolve:{
         resB: function(resA){
            return {'value': resA.value + 'B'};
         }
      },
      controller: function($scope, resA, resB){
          $scope.resA2 = resA.value;
          $scope.resB = resB.value;
      }

来源

这篇关于angularjs - 刷新子状态视图原因丢失的数据从父状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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