Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获引用错误:未定义require_Javascript_Cordova - Fatal编程技术网

Javascript 未捕获引用错误:未定义require

Javascript 未捕获引用错误:未定义require,javascript,cordova,Javascript,Cordova,我正在尝试实现cordova plugin email composer。我使用cli cordova插件添加https://github.com/katzer/cordova-plugin-email-composer.git 我收到一个错误uncaughtreferenceerror:require未在email\u composer.js:22中定义。 在u中可以找到插件。我在我的index.js文件中添加了下面附加的代码。有人能帮忙解决这个问题吗?谢谢 index.js: bindEve

我正在尝试实现
cordova plugin email composer
。我使用
cli

cordova插件添加https://github.com/katzer/cordova-plugin-email-composer.git

我收到一个错误
uncaughtreferenceerror:require未在email\u composer.js:22中定义。

在u中可以找到插件。我在我的
index.js
文件中添加了下面附加的代码。有人能帮忙解决这个问题吗?谢谢

index.js:

bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, function () {
        cordova.plugins.email.isAvailable(
            function (isAvailable) {
                alert("is email mobile available? " + (isAvailable ? "Yes" : "No"));
                if(isAvailable){
                 window.plugin.email.open({
                     to:      'anu.barbie143@gmail.com',
                     subject: 'Greetings',
                     body:    'How are you? Nice greetings from Leipzig'
                 }, callback, scope);
               }
            }
        );
    }, false);

    function callback(){
        console.log("callback function");
    }

    function scope(){
        console.log("scope function");
    }

},
电子邮件_composer.js:

var exec      = require('cordova/exec'),
isAndroid = navigator.userAgent.toLowerCase().indexOf('android') > -1,
mailto    = 'mailto:';
在上面的代码中,我得到一个错误,要求没有定义。有人能帮我解决这个问题吗?
谢谢。

我是通过做以下几件事才成功的

cordova plugin rm cordova-plugin-email-composer
然后通过以下命令添加版本为0.8.2的插件,因为loolipop的插件版本0.8.3中存在打开错误

cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git#0.8.2
index.js

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');

                cordova.plugins.email.open({
                    to:      'test@gmail.com',
                    cc:      'test@gmail.com',
                    bcc:     [],
                    subject: 'Greetings',
                    body:    'How are you? Nice greetings from Naresh'
                });



    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

希望它对您有所帮助。

我现在修改了您的代码及其工作方式。 所以请检查一下

cordova.plugins.email.isAvailable(function (isAvailable) {
                // alert('Service is not available') unless isAvailable;
                alert("is email mobile available? " + (isAvailable ? "Yes" : "No"));
                if(isAvailable){
                    window.plugin.email.open({
                        to:      'test@test.com',
                        subject: 'Greetings',
                        body:    'How are you? Nice greetings from Leipzig',
                    }, function(){
                        console.log('email view dismissed');
                    },
                    this);
                }
            });

如果警报为“否”,则表示您没有任何电子邮件应用程序或配置。

您使用的是哪个版本的电子邮件生成器?版本-0.8。3@Hitenonce已删除插件并将再次添加。您是否收到警报“电子邮件移动设备可用…”?我尝试删除,然后再次添加相同的错误。没有,我无法收到警报。@HitenYou没有直接从
index.html
中引用
email\u composer.js
,对吗?