2015-09-08 55 views
0

我正在關注ngCordova的這個官方文檔,發送一封電子郵件 電子郵件作曲者插件與ngCordova。如何從html中調用ngCordova插件

的angularJs控制器:

module.controller('ThisCtrl', function($cordovaEmailComposer) { 

$cordovaEmailComposer.isAvailable().then(function() { 
    // is available 
}, function() { 
    // not available 
}); 

    var email = { 
    to: '[email protected]', 
    cc: '[email protected]', 
    bcc: ['[email protected]', '[email protected]'], 
    attachments: [ 
     'file://img/logo.png', 
     'res://icon.png', 
     'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...', 
     'file://README.pdf' 
    ], 
    subject: 'Cordova Icons', 
    body: 'How are you? Nice greetings from Leipzig', 
    isHtml: true 
    }; 

$cordovaEmailComposer.open(email).then(null, function() { 
    // user cancelled email 
}); 
}); 

如何從HTML頁面調用此? 我想按下按鈕時,會調用此代碼,但在其官方網頁中沒有完整示例

回答

0

我走,你可能已經找到了答案從那時起,但我有同樣的問題比你,所以我只是嘗試了一些東西,這對我的作品:

<html> 
    <head> 
    <script> 
    var app = angular.module('propertyDeal', ['ngCordova']); 
     app.controller('ThisCtrl', function($scope, $cordovaEmailComposer) { 

     $scope.email = function() { 
      document.addEventListener("deviceready", function() { 

       $cordovaEmailComposer.isAvailable().then(function() { 
        alert("email available"); 
       }, function() { 
        alert = ("email not available"); 
       }); 

       var email = { 
       to: '[email protected]', 
       cc: '[email protected]', 
       bcc: ['[email protected]', '[email protected]'], 
       attachments: [ 
        'file://img/logo.png', 
        'res://icon.png', 
        'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...', 
        'file://README.pdf' 
       ], 
       subject: 'Cordova Icons', 
       body: 'How are you? Nice greetings from Leipzig', 
       isHtml: true 
      }; 

      $cordovaEmailComposer.open(email).then(null, function() { 
       alert("email not sent"); 
      }); 

     }, false); 
     } 
    }); 
</script> 
</head> 

<body> 
    <div ng-controller="ThisCtrl"> 
     <button class="button" ng-click="email()">Send an email</button> 
    </div> 
    <script type="text/javascript" src="components/ngCordova/ng-cordova.min.js"></script> 
    <script type="text/javascript" src="cordova.js"></script> 
</body> 
</html> 

不大確定它是正確的做法,但它的工作原理...