how to make nested ui-router execute child controller every route change

匆匆过客 提交于 2019-12-11 10:22:37

问题


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.

Is someone could help me?

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

回答1:


Check these:

  • 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

  • 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


来源:https://stackoverflow.com/questions/34415782/how-to-make-nested-ui-router-execute-child-controller-every-route-change

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