javascript - Ionic 2 正在加载过时的组件

标签 javascript android angular ionic-framework ionic2

这是我的页脚组件。我从页脚栏中调用几页,如下所示。当我单击页脚时,它正在加载过时的组件。我调试了它,发现它没有调用组件的构造函数(我有加载逻辑来刷新数据)。我必须从页脚单击两次才能调用组件才能获取正确的数据

tab-footer.component.html

  <ion-tabs>
    <ion-tab [root]="home" tabIcon="md-home" 
   [rootParams]="homeparams"></ion-tab>
     <ion-tab [root]="alertsPage" tabIcon="md-notifications-outline">
    </iontab>
   <ion-tab [root]="flagged" tabIcon="flag"></ion-tab>
  </ion-tabs>


  @Component({
   selector: 'app-tab-footer',
   templateUrl: './tab-footer.component.html',
  styleUrls: ['./tab-footer.component.scss']
  })
  export class TabFooterComponent {

  home = HomeComponent;
  alertsPage = AlertsComponent;
  flagged = FlaggedComponent;
  homeparams: any;

  constructor(public navparam: NavParams) {
    this.homeparams = navparam;
   }

 }

这是我从页脚调用的组件之一

  @Component({
 selector: 'app-flagged',
 templateUrl: './flagged.component.html',
  styleUrls: ['./flagged.component.scss']
})
export class FlaggedComponent {

    someData1: any;
    someData:any[] = [];

    someObj = {}

 constructor(public someService: SomeServiceService,
     public exampleService: ExampleService,
     public navParams: NavParams,
     public navCtrl: NavController) {

   // some loading logic
   }

任何人都可以帮忙找出为什么它不每次都调用构造函数吗? 我是否指定了一些属性来加载它? 谢谢

最佳答案

将生命周期事件 ionViewDidEnterionViewWillEnter 添加到您的 FlaggedComponent 类,并将更新或加载逻辑从构造函数移动到这些方法之一.

ionViewDidEnter() {
  console.log('the page has entered');
}

ionViewWillEnter() {
  console.log('the page is about to enter');
}

ionViewDidEnter is called when the page has fully entered and is now the active page. This event will fire, whether it was the first load or a cached page.

ionViewWillEnter is called when the page is about to enter and become the active page.

引用:https://ionicframework.com/docs/api/navigation/NavController/#lifecycle-events

关于javascript - Ionic 2 正在加载过时的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47665407/

相关文章:

arrays - 从 Json Angular 5 插入数组

angular - 运行 headless Chromium 浏览器会抛出错误 'Failed to read DnsConfig'(在 Docker 容器内)

java - 问题追踪网络 "stability"问题根源

android - 更新表无法正常工作

javascript - easyui 添加整列

javascript - 无法访问 svg 路径属性

android - android添加依赖报错

javascript - Angular 如何动态更改数组中的值

javascript - react native 。应用程序的关闭事件

javascript - 在 AngularJS 代码中使用此扩展的正确方法是什么?