question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LoadingController: TypeError: Cannot read property 'present' of undefined

See original GitHub issue

Bug Report

Ionic version:

[x] 4.x

Current behavior:

When attempting to create a new loadingController, and when attempting to call any method on it, I receive the below error in my browser console: TypeError: Cannot read property 'present' of undefined

I am using Ionic with Capacitor. I’m not sure if the issue should be filed with them or Ionic. I figured I would start here, since the issue is with Ionic’s loadingController feature.

Expected behavior: I should not be receiving this error, and this.loading should be defined.

Steps to reproduce:

  1. Instantiate a new loadingController with await this.$ionic.loadingController.create()
  2. Attempt to call any method on it
  3. Receive an error that the newly created loadingController is undefined

Related code:

async presentLoading() {
            this.loading = await this.$ionic.loadingController.create();
            return await this.loading.present();
},

Other information:

Same issues as:

Ionic info:

Ionic:

   ionic (Ionic CLI) : 4.5.0 (/usr/local/lib/node_modules/ionic)

System:

   NodeJS : v9.11.1 (/usr/local/bin/node)
   npm    : 6.5.0
   OS     : macOS Mojave

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
uriannrimacommented, Apr 26, 2019

So, I’ve found a workaround for my issue trying to create a loading inside the vue’s mounted hook. I’ve simple added a setTimeout and created inside of it… As I was hoping that the problem was that the ionic hasn’t yet “kicked” in, and created the ion-loading-controller, so I’ve created a timeout to push the loading creation in the call stack, and well… it worked.

Before:

  async mounted() {
    const loader = await this.$ionic.loadingController.create({
      message: "Loading characters..."
    });
    loader.present();
    await this.loadCampaigns();
    loader.dismiss();
  },

After:

  async mounted() {
    setTimeout(async () => {
      const loader = await this.$ionic.loadingController.create({
        message: "Loading characters..."
      });
      loader.present();
      await this.loadCampaigns();
      loader.dismiss();
    }, 0);
  }
0reactions
ionitron-bot[bot]commented, Sep 24, 2020

Thanks for the issue! This issue is being closed due to the lack of a reply. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Thank you for using Ionic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

LoadingController: TypeError: Cannot read property 'present ...
Receive an error that the newly created loadingController is undefined. Related code: async presentLoading() { this.loading = await this.$ionic.
Read more >
TypeError: Cannot read property 'dismiss' of undefined in ionic ...
Create a hideLoading() method like below can call it when you want to hide the loading circle. async hideLoading() { this.loadingController.
Read more >
LoadingController not injected in the component and remains ...
ERROR TypeError: Cannot read properties of undefined (reading 'create') at SafeSubscriber.showLoading [as _next] (login.page.ts:61).
Read more >
[Solved]-How to fix cannot read property 'dismiss' of undefined ...
The easiest fix is to turn this into any, there is no such Element name HTMLIonLoadingElement - or if its an interface you...
Read more >
Using LoadingController in Ionic 4 — waiting for API response
In the “Case 1”, we are calling present() method on our instance of loading controller which is returning Promise and when it shows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found