离子-未捕获(承诺):TypeError:无法读取未定义的属性'then'

计算机科学

在我的离子应用程序运行期间出现此错误。我试图实现Ionic“ Email Composer”库以从客户端发送电子邮件,请参考此链接以了解我所关注的代码;[ https://ionicframework.com/docs/native/email-composer][1]错误的流程是当我测试应用程序时,我按下了触发“ LoadingDialog”功能的按钮,该功能触发了发生错误的“ SendEmail”功能。我不确定如何解决此错误,但我认为这与我尚不了解的Promise的语法有关。感谢您提供任何帮助!

错误中出现的代码行

this.emailComposer.isAvailable()。then((available:boolean)=> {// <<<<<<<<这是home.page.ts文件中的221行,它出现在错误中

this.SendEmail(); // <<<<<<<<这是home.page.ts文件中的109行

错误

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.<anonymous> (home.page.ts:109)
     at Generator.next (<anonymous>)
     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)

代码(home.page.ts)

            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(); //<<<<<<<< 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("header");
        }

        SendEmail(){
                this.emailComposer.isAvailable().then((available: boolean) =>{  //<<<<<<<< THIS IS LINE 221 IN home.page.ts file
                    if(available) {
                    //Now we know we can send
                    this.RegularAlert("testing the isAvailable().then", "available is true");//print a debug message to test functionality of   

                    let email = {
                        to:'[email protected]',
                        cc: '[email protected]',
                        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("testing the isAvailable().then", "available is false");
                    }
                });

        } 

    }
计算机科学

发生此错误的原因是,我没有在模拟器或Android手机中运行该应用程序,因为Cordova库仅与移动操作系统(如Android OS)一起运行。您需要的最低要求是:

如果(this.platform.is('cordova')){//在此处运行电子邮件编写器代码}

我在Android手机上运行代码后,此代码为我工作了:

if (this.platform.is('cordova')){//use this for android,iOS,Windows-Mobile,etc){
            try {
                this.emailComposer.isAvailable().then((available: boolean) =>{
                    if(available) {
                        //Now we know we can send
                        let email = {
                            to: '[email protected]',
                            cc: '[email protected]',
                            bcc: [],
                            attachments: [],
                            subject: 'Cordova Icons',
                            body: 'How are you? Nice greetings from Leipzig',
                        isHtml: false
                        }//email object close

                    //Send a text message using default options
                    this.emailComposer.open(email);//opens user prompt to use third party email app with the email message above.
                    }//if close 
                    else{
                        console.log("Rare Error inside of the promise returned by the emailComposer.isAvailable()", "promise error");//TEST PRINT
                    }
                });
            } catch(e){
                  //catches the "this.emailComposer.isAvailable()" variable if the email composer plugin is not available on the installed phone   
            }
        }//if this.platform.is close
        else{
            console.log("Platform is not cordova/mobile","You are running in browser, this.emailComposer.isAvailable() is undefined.");//TEST PRINT
        }//else close

这是电子邮件编辑器的源代码:https : //ionicframework.com/docs/native/email-composer

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

业力| 离子| 未捕获的错误:未捕获的错误:未捕获(在承诺中):TypeError:无法读取未定义的属性'getToken'

无法读取未定义离子的属性“子级”

无法读取离子中未定义的属性“ udp”

离子设置推送-无法读取未定义的属性

离子的:$ cordovaSocialSharing无法读取未定义的属性

离子吐司消息无法读取未定义的属性“创建”

角离子电容器构建产品:TypeError 无法读取未定义的“updateClassDeclaration”的属性

离子 2 模态。内联模板 - TypeError:无法读取未定义的属性“items”

承诺中未定义的离子存储?

未捕获(承诺):错误:无法读取未定义的属性

未捕获(承诺)TypeError:无法读取未定义的属性“ forEach”

“错误:未捕获(承诺):TypeError:无法读取未定义的属性'length'”

错误错误:未捕获(承诺):TypeError:无法读取未定义的属性 - Typescript

未捕获(承诺)TypeError:无法读取未定义的属性'createElement'(...)

未捕获(承诺)TypeError:无法读取未定义的属性“ setState”

如何修复Cloudflare worker中的“未捕获(承诺)TypeError:无法读取未定义的属性“方法””?

未捕获(承诺)TypeError:无法读取未定义的属性“ map”-但以前可以正常工作吗?

ML5,情绪分析:未捕获(按承诺)TypeError:无法读取未定义的属性“ the”

错误:未捕获(承诺):TypeError:无法读取未定义的属性“ title”

错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ id”

React + Axios:未捕获(承诺)TypeError:无法读取未定义的属性“map”

VueJS和Firestore-未捕获(承诺)TypeError:无法读取未定义的属性

Angular 2-未捕获(承诺):TypeError:无法读取未定义的属性“ title”

Axios:未捕获(已承诺)TypeError:无法读取未定义的属性“协议”

topojson / d3.js:未捕获(承诺)TypeError:无法读取未定义的属性“ type”

React Redux-未捕获(承诺)TypeError:无法读取未定义的属性“ props”

未捕获(承诺):TypeError:无法读取未定义的属性“ people”

未捕获(承诺)TypeError:无法读取未定义的属性“httpsCallable”(Firebase 函数问题)

未捕获(承诺)TypeError:无法读取未定义的属性“ geometry”