how to make nested ui-router execute child control

2019-08-12 22:08发布

问题:

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