Call function from another page / controller

I searched here on the forum for some solution but I found some complicated.
I am learning to use the angular / ionic.

I have a function that updates a list through an event, and I would like to call another function on another page to update that counts the total items in the list.

I will be grateful to anyone who can help me ^^

page1:

 doRefresh(event)
 {
    setTimeout(() => {
     this.sTxt = null;
     this.sTipo = 0;
      this.ngOnInit();
      event.target.complete();
      this.start = 0;
    }, 500);
 }

page2:

carregar()
   {
       let dados = { requisisao: 'hTotal' };
 
       this.provider.Api(dados, 'api.php').subscribe(async data => {
 
         if(data['success'])
         {
           this.hTotal = data['total'];
           console.log(data);
         }
         else { this.hTotal = 0; }
       });
   }

i think you should use service for that. make one service and create your function within it then use that service in both page.

1 Like

In addition to @hirenkorat3ā€™s excellent advice above, I am very suspicious of setTimeout, especially with magic numbers. What is that doing there?

Iā€™m using ion-refresher

Then I would totally reverse the way your code is organized. Lifecycle events like ngOnInit are designed to be called from the framework, not from app code. Instead, have ngOnInit call doRefresh, which will allow doRefresh to return a future indicating when it has done its job, and you can use that to determine when to call target.complete, not a random arbitrary delay.