title: How to stop functions when leaving the page in Ionic 4
body: <p>I am working in my Ionic 4 app and I want to stop the functions when the page will leave.</p>
  
  <p>This is my <strong>tab4.page.ts</strong>:</p>
  
  <pre><code>async getUserDetail(){ 
      this.dataexists = false;
      this.userActiveChallanges = [];   
      let me=this;   
      const loading = await this.loadingController.create({
        message: '',
        // duration: 2200,
        translucent: true,
        spinner: 'crescent',
        showBackdrop: false,
        cssClass: 'my-loading-class'
      });
      await loading.present();  
      this.userActiveChallanges=[];
      this.storage.get('USERPROFILE').then(userObj =&gt; { 
        // console.log('User Profile :',userObj);
        me.userprofile = userObj; 
        me.sendFitDatafunction(userObj);
        me.myapi.apiCall('userActiveChallenges/'+userObj.id,'GET','').subscribe((data) =&gt; {
          // console.log(data); 
          me.response=data;       
          loading.dismiss();
          if(me.response.status === 'success'){
            if(me.response &amp;&amp; me.response.data &amp;&amp; me.response.data.length&gt;0){
              this.userActiveChallanges=me.response.data;
              this.flip(this.userActiveChallanges[0].challenge_id);
            }
            this.dataexists = true;
          } else{
            this.userActiveChallanges = '';
            this.dataexists = true;
          }
  
        }, error =&gt; { loading.dismiss(); console.log(error); });
  
      });
    }
  
    ionViewWillLeave() {
  
    }
  </code></pre>
  
  <p>I want to stop this function when the page will leave because when I am not getting any response nor any error from the api the loader keeps running and when I move to the other page, it is showing there.</p>
  
  <p>So, I want to stop the function when the page will leave.</p>
  
  <p>Any help is much appreciated.</p>