title: Error: Uncaught (in promise): TypeError: Cannot read property 'dismiss' of undefined in ionic 5
body: <p>I am building an app with ionic 5, i want to show ion-loader when a user tries to login, and after a response is gotten from the server, it will dismiss the ion-loader, but when i tried it, i got this error</p>
  
  <pre><code>Error: Uncaught (in promise): TypeError: Cannot read property 'dismiss' of undefined
  </code></pre>
  
  <p>here is my code</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { HomePage } from '../home/home.page';
  import { NavController, AlertController, LoadingController } from '@ionic/angular';
  import { AuthServiceService } from '../auth-service.service';
  
  @Component({
      selector: 'app-login',
      templateUrl: './login.page.html',
      styleUrls: ['./login.page.scss'],
  })
  export class LoginPage implements OnInit {
  
      ngOnInit() {
      } 
    registerCredentials = { email: '', password: '' };
    loaderToShow: any;
    constructor(
      public navCtrl: NavController, 
      private auth: AuthServiceService,
      private alertCtrl: AlertController,
      private loadingCtrl: LoadingController
    ) {
      console.log(this.registerCredentials);
    }
  
    public login() {
      this.showLoading();
      this.auth.login(this.registerCredentials).subscribe(allowed =&gt; {
        if (allowed) {        
          this.loaderToShow.dismiss();
          console.log('canceal')
        } else {
          this.showError('Access Denied');
        }
      }, error =&gt; {
        this.showError(error);
      });
    }
  
    public async showLoading() {
      this.loaderToShow = await this.loadingCtrl.create({
          message: 'Please Wait...'
      });
      await this.loaderToShow.present();
    }
  
  
    public async showError(text) {
      this.loaderToShow.dismiss();
  
      let alert = await this.alertCtrl.create({
          header: 'Fail',
          message: text,
        buttons: ['OK']
      });
      await alert.present();
    }
  
  }
  </code></pre>
  
  <p>Pls how can i properly dismiss the ion-loader</p>