每次访问 View 时都重新初始化 Controller - Ionic Framework [英] Reinitialize Controller every time when visiting View - Ionic Framework

查看:25
本文介绍了每次访问 View 时都重新初始化 Controller - Ionic Framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有两个视图,每个视图都分配了两个控制器.每次导航到特定视图时,我都需要重新初始化控制器.

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.

角度脚本:

.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 内容

<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>

我尝试在堆栈上实现许多解决方案,但没有一个对我有帮助.尝试过的解决方案 1/尝试过的解决方案 2

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

推荐答案

如果是 View 没有更新的问题,禁用缓存可能会有帮助

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

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

默认情况下,视图会被缓存以提高性能.您还可以通过 'cache-view' 属性禁用缓存

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>

这篇关于每次访问 View 时都重新初始化 Controller - Ionic Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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