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

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

问题描述

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

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');

推荐答案

检查以下内容:

  • What is the difference between $ionicView.enter and cache:false
  • ui.router not reloading controller

您将看到,离子确实为我们缓存了所有东西.为了避免,我们可以

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期间进行一些智能操作时
  • avoid caching by cache: false,
  • disable caching with $ionicConfigProvider.views.maxCache(0);
  • or keep caching as is, and let controller be executed only once ... while doing some smart stuff during these View LifeCycle and Events

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

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