简体   繁体   中英

How to refresh page on click (ionic v4)

Trying to refresh a page when the user deletes data. Some Html elements on the page automatically update, but the main app component holds onto the old data until the page is manually refreshed.

ionViewWillEnter() no longer works as illustrated in this example: How to refresh page in ionic 4

I tried using ngOnInit() instead, but that didn't work. I've also tried ChangeDetectorRef, but no joy.

typescript


import { ChangeDetectorRef } from '@angular/core'

public contentId: any;
public content: any;

constructor(private changeRef: ChangeDetectorRef) {
  ...
}

ngOnInit() {
  this.fetchData();
}

fetchData() {
  ...
  this.database.get(contentId).subscribe( content => {
    this.content = content[0];
 });
}

deleteData() {
  this.content.delete(id);
  this.changeRef.detectChanges();
}

Html

<app-content *ngIf="contentId" [pageContent]="contentId"></app-content>

data from this.content

{
 id: 'contentId',
 text: 'some text',
 author: 'username',
 uid: 'userId'
}

Try with ionViewWillEnter

  ionViewWillEnter() {
        this.fetchData();
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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