无法阅读属性'插件'在Object.isAvailable中未定义

时间:2016-06-14 09:28:22

标签: cordova ionic-framework cordova-plugins

我正在尝试使用cordova / ionic发送电子邮件,但我收到上述错误。我已经按照我想要遵循的所有步骤进行操作,并且我已经阅读了与此相关的其他文章,但仍然无法找到溶液

index.html是

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
      <meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org">

      <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
<script src="lib/ng-cordova-master/dist/ng-cordova.js"></script>

    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <!--<script src="js/EmailComposer.js"></script>-->
  </head>
  <body ng-app="starter">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Blank Starter</h1>
      </ion-header-bar>
      <!--<ion-content ng-controller="EmailController">-->
      <ion-content ng-controller="EmailCtrl">
          <!--<button class="button" ng-click="sendFeedback">-->
              <!--Send messege-->
          <!--</button>-->
          <button ng-click="sendEmail()" class="button button-icon icon ion-email"style="padding-top: 100px">
              Send mail
          </button>

      </ion-content>
    </ion-pane>
  </body>
</html>

app.js是

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
//var exampleApp = angular.module('starter', ['ionic','ngCordova'])
var app =angular.module('starter', ['ionic','ngCordova'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

    .controller('EmailCtrl',[ "$cordovaEmailComposer", function($cordovaEmailComposer, $scope) {
        $cordovaEmailComposer.isAvailable().then(function() {
            // is available
            alert("available");
        }, function () {
            // not available
            alert("not available");
        });
        $scope.sendEmail = function(){
            var email = {
                to: 'adishri.28@gmail.com',
                cc: 'adishri.28@gmail.com',
                bcc: ['adishri.taarago.com', 'adishri.taarago.com'],
                //attachments: [
                //    'file://img/logo.png',
                //    'res://icon.png',
                //    'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...',
                //    'file://README.pdf'
                //],
                subject: 'Mail subject',
                body: 'How are you? Nice greetings from Leipzig',
                isHtml: true
            };

            $cordovaEmailComposer.open(email).then(null, function () {
                // user cancelled email
            });
        }
    }]);
//exampleApp.controller('EmailController', function($scope) {
//  $scope.sendFeedback= function() {
//    if(window.plugins && window.plugins.emailComposer) {
//      window.plugins.emailComposer.showEmailComposerWithCallback(function(result) {
//            console.log("Response -> " + result);
//          },
//          "Feedback for your App", // Subject
//          "",                      // Body
//          ["adishri.28@gmail.com"],    // To
//          null,                    // CC
//          null,                    // BCC
//          false,                   // isHTML
//          null,                    // Attachments
//          null);                   // Attachment Data
//    }
//  }
//});

任何人都可以帮我解决这个问题吗? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

尝试在真实设备或模拟器上进行测试。控制器似乎很难找到插件,当我尝试实现cordovaClipboard时,我遇到了同样的错误,当我使用离子服务运行它时,我得到了错误,但一切都是&# 39;如果我在手机上运行它,那很好。