Reinitialize Controller every time when visiting View - Ionic Framework

五迷三道 提交于 2019-12-11 09:45:03

问题


Hi i'm having two views in my app with two controllers assigned to each. Here i need to reinitialize the controller every time when ever i navigate to particular view.

Angular Script:

.state('app.pnrlist', {
            url: "/pnrlist",
            views: {
                'menuContent': {
                    templateUrl: "templates/test.html",
                    controller: "testControl",
                    reload: true
                }
            },
            reload:true
        })

        .state('app.home', {
            url: "/home",
            views: {
                'menuContent': {
                    templateUrl: "templates/home.html",
                    controller:"homeControl",
                    reload:true
                }
            },
            reload:true
        })

HTML Content

<ion-content>
  <ion-list>
    <ion-item nav-clear menu-close href="#/app/home">
      Home
    </ion-item>
      <ion-item nav-clear menu-close href="#/app/pnrlist">
          PNR List
      </ion-item>
  </ion-list>
</ion-content>

I have tried to implement many solutions on stack but none helped me. Solution Tried 1 / Solution Tried 2


回答1:


If its a matter of the View not updating, disabling the Cache may help

i.e

.state('app.home', {
   url: "/home",
   cache: false,

As by default, views are cached to improve performance. You can also disable the cache via the 'cache-view' attribute

<ion-view cache-view="false" view-title="My Title!">
  ...
</ion-view>


来源:https://stackoverflow.com/questions/31085034/reinitialize-controller-every-time-when-visiting-view-ionic-framework

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