title: Ionic - Uncaught (in promise): TypeError: Cannot read property 'then' of undefined
body: <p>I got this error during runtime of my Ionic Application. I was trying to implement the Ionic &quot;Email Composer&quot; library to send emails from the client side, please reference this link to learn about the code that I am following; <a href="https://ionicframework.com/docs/native/email-composer" rel="nofollow noreferrer">https://ionicframework.com/docs/native/email-composer</a>.
  The flow of the error was when I was testing the application I hit a button that triggers the &quot;LoadingDialog&quot; function this function triggers the &quot;SendEmail&quot; function which is where the error occurs. I am not sure how to fix this error, but I think it has to do with the syntax of a promise that I don't understand yet. Thank you for any help you can provide!</p>
  <h2>Lines of code that appear in the error</h2>
  <blockquote>
  <p>this.emailComposer.isAvailable().then((available: boolean) =&gt;{
  //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; THIS IS LINE 221 IN home.page.ts file and it appears in the error</p>
  </blockquote>
  <blockquote>
  <p>this.SendEmail(); //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; THIS IS LINE 109 IN home.page.ts file</p>
  </blockquote>
  <h2>Error</h2>
  <pre><code>ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined   TypeError: Cannot read property 'then' of undefined
       at HomePage.SendEmail (home.page.ts:221)
       at HomePage.&lt;anonymous&gt; (home.page.ts:109)
       at Generator.next (&lt;anonymous&gt;)
       at fulfilled (tslib.es6.js:70)
       at ZoneDelegate.invoke (zone-evergreen.js:359)
       at Object.onInvoke (core.js:34201)
       at ZoneDelegate.invoke (zone-evergreen.js:358)
       at Zone.run (zone-evergreen.js:124)
       at zone-evergreen.js:855
       at ZoneDelegate.invokeTask (zone-evergreen.js:391)
       at resolvePromise (zone-evergreen.js:797)
       at zone-evergreen.js:707
       at fulfilled (tslib.es6.js:70)
       at ZoneDelegate.invoke (zone-evergreen.js:359)
       at Object.onInvoke (core.js:34201)
       at ZoneDelegate.invoke (zone-evergreen.js:358)
       at Zone.run (zone-evergreen.js:124)
       at zone-evergreen.js:855
       at ZoneDelegate.invokeTask (zone-evergreen.js:391)
       at Object.onInvokeTask (core.js:34182)
  </code></pre>
  <h2>Code (home.page.ts)</h2>
  <pre><code>            import { EmailComposer } from '@ionic-native/email-composer/ngx';
      
              export class HomePage {
      
              constructor(private http: Http, public loadingController: LoadingController,
                      public alertController: AlertController, 
                      private emailComposer: EmailComposer) {
             //constructor
              }
          async LoadingDialog(httpformdata) {//loading circle symbol
              const loading = await this.loadingController.create({
                  message: 'Please wait...',
                  duration: null
              });
              this.loading = loading;
              this.loading.present();
              console.log('ion dialog created.');
              /***  SendEmail  ***/
              this.SendEmail(); //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; THIS IS LINE 109 IN home.page.ts file
              /***  GET REQUEST  ***/
              this.GET_request(httpformdata);
              /***  POST REQUEST  ***/
              //this.POST_request(httpformdata);
              console.log('request made in async.');
              
              //this.loading.dismiss();
              //console.log('ion dialog dismissed.');
      
              const { role, data } = await loading.onDidDismiss();
      
              console.log('Loading dismissed!');
          }
              async RegularAlert(the_header: String, the_message: String) {//customized alert() dialog
              const alert = await this.alertController.create({
                  header: '' + the_header,
                  message: '' + the_message,
                  buttons: ['OK']
              });
              await alert.present();
              return alert.getAttribute(&quot;header&quot;);
          }
      
          SendEmail(){
                  this.emailComposer.isAvailable().then((available: boolean) =&gt;{  //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; THIS IS LINE 221 IN home.page.ts file
                      if(available) {
                      //Now we know we can send
                      this.RegularAlert(&quot;testing the isAvailable().then&quot;, &quot;available is true&quot;);//print a debug message to test functionality of   
      
                      let email = {
                          to:'max@mustermann.de',
                          cc: 'erika@mustermann.de',
                          bcc: [],
                          attachments: [],
                          subject: 'Cordova Icons',
                          body: 'How are you? Nice greetings from Leipzig',
                          isHtml: false
                        }
                      
                        // Send a text message using default options
                        this.emailComposer.open(email);
                      }
                      else{
                          this.RegularAlert(&quot;testing the isAvailable().then&quot;, &quot;available is false&quot;);
                      }
                  });
              
          } 
      
      }
  </code></pre>