如何使嵌套的 ui-router 每次路由更改都执行子控制器 [英] how to make nested ui-router execute child controller every route change

查看:26
本文介绍了如何使嵌套的 ui-router 每次路由更改都执行子控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的ui-router配置.我希望每次更改子状态时都会执行子控制器.但是现在,子控制器仅在我第一次更改子状态时执行.

The following is my ui-router configuration. I hope that the child controller will be executed when I change the child state every time. But now, the child controller be executed only the first time I change the child state.

有人可以帮助我吗?

 $stateProvider
    .state('tab', {
        url: '/tab',
        abstract: true,
        templateUrl: 'views/tabs.html'
    })
    .state('tab.order-foods',{
        url:'/order-foods',
        views:{
            'tab-order-foods':{
                templateUrl:'../views/tab-order-foods.html',
                controller:'orderFoodsCtrl'
            }
        }
    })
    .state('tab.cart',{
        url:'/cart',
        views:{
            'tab-cart':{
                templateUrl:'../views/tab-cart.html',
                controller:'cartCtrl'
            }
        }
    })
    .state('tab.orders',{
        url:'/orders',
        views:{
            'tab-orders':{
                templateUrl:'views/tab-orders.html',
                controller:'ordersCtrl'
            }
        }
    })
    .state('tab.mine',{
        url:'/mine',
        views:{
            'tab-mine':{
                templateUrl:'views/tab-mine.html',
                controller:'mineCtrl'
            }
        }
    });
$urlRouterProvider.otherwise('/tab/order-foods');

推荐答案

检查这些:

你会看到,ionic 确实为我们缓存了所有的东西.为了避免我们可以

And you will see, that ionic does cache all the stuff for us. To avoid we can

  • 通过cache: false,
  • 避免缓存
  • 使用 $ionicConfigProvider.views.maxCache(0);
  • 禁用缓存
  • 或者保持缓存不变,让控制器只执行一次......同时在这些 View LifeCycle 和 Events 期间做一些聪明的事情

这篇关于如何使嵌套的 ui-router 每次路由更改都执行子控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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