简体   繁体   English

$ state.go()不会在离子应用程序中加载控制器

[英]$state.go() doesn't load controller in ionic application

Using the following code, when a page with id=0 loads first time there is no problem with controller. 使用以下代码,当第一次加载id=0的页面时,控制器没有问题。 But when again the same page loads with same id=0 again, it does not loads controller. 但是当同一页面再次加载相同的id=0时,它不会加载控制器。

$state.go('tab.dash', {
  id: $rootScope.products[CONSTANTS.i].id
}, {
  reload: true
});

How does it happen? 怎么会发生? Please suggest me a solution. 请建议我一个解决方案。

I encountered a similar problem where I needed stats to recalculate every time a tab was visited. 我遇到了类似的问题,我每次访问标签时都需要重新计算统计数据。

You need to disable view caching. 您需要禁用视图缓存。 You can do so in the route setup. 您可以在路径设置中执行此操作。 For example: 例如:

.state('tab.stats', {
 url: '/stats',
 views: {
   'tab-stats': {
     templateUrl: 'templates/tab-stats.html',
     controller: 'StatsCtrl'
   }
 },
 cache: false
})

well, When you cache the view (by default it is true) controller is loaded only at first time and on subsequent navigation it will attach and detach the scope. 好吧,当您缓存视图时(默认情况下为true),控制器仅在第一次加载时,在后续导航中,它将附加和分离范围。 Cacheing helping with the performance of single page applications. 缓存有助于提高单页应用程序的性能。 If you dont want to disable the caching then you use the ionic view events like (enter, leave,loaded and so on). 如果您不想禁用缓存,则使用离子视图事件,如(输入,离开,加载等)。

 $scope.$on('$ionicView.enter', function () {
            // ur stuff in here....
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM