2017-04-07 73 views
1

我想实现cordova-plugin-email-composer。我安装使用cli未捕获的ReferenceError:要求没有定义

cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git

我得到一个错误Uncaught ReferenceError: require is not defined at email_composer.js:22.

link 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:  '[email protected]', 
        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"); 
    } 

}, 

email_composer.js:

var exec  = require('cordova/exec'), 
isAndroid = navigator.userAgent.toLowerCase().indexOf('android') > -1, 
mailto = 'mailto:'; 

在上面的代码中,我得到一个错误要求不defined.Can任何人帮我解决这个问题? Thankyou。

+0

您使用哪种版本的电子邮件作曲家? – Hiten

+0

版本[email protected] – Anusha

+0

一旦删除插件,将再次添加。你有没有注意到“电子邮件手机可用...”? – Hiten

回答

1

我把它做以下

cordova plugin rm cordova-plugin-email-composer 

然后用0.8.2版本添加插件,通过由于在插件0.8.3版本开放的错误loolipop以下命令工作

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:  '[email protected]', 
        cc:  '[email protected]', 
        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(); 

希望它可以帮助你..

+0

@Anusha,如果它在工作,请接受答案 –

+0

其工作[email protected]库马尔 – Anusha

0

我修改了你的代码,现在就开始工作。 所以请检查一次。

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:  '[email protected]', 
         subject: 'Greetings', 
         body: 'How are you? Nice greetings from Leipzig', 
        }, function(){ 
         console.log('email view dismissed'); 
        }, 
        this); 
       } 
      }); 

如果警报是“否”就意味着你没有任何电子邮件应用程序或配置。

相关问题