2017-04-07 75 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); 
       } 
      }); 

如果警報是「否」就意味着你沒有任何電子郵件應用程序或配置。

相關問題