cordova中的CallLog访问插件无法正常工作

Sun*_*ash 10 android angularjs cordova

嗨,我正在使用cordova开发混合应用程序.我试图使用CallLog插件访问在Android手机中错过的最后一个电话.这是我试过的,

1.I installed the plugin with this command cordova plugin add https://github.com/dalyc/Cordova-CallLog-Plugin.git.
2.I am using angularJS.I have this app.js.

var app=angular.module('lmp', ['ngCordova']);
     app.controller('lmpctrl',['$scope', 'CallLogService', function($scope, CallLogService){
        $scope.data = {};
                $scope.callTypeDisplay = function(type) {
                    switch(type) {
                        case 1:
                            return 'Incoming';
                        case 2:
                            return 'Outgoing';
                        case 3:
                            return 'Missed';
                        default:
                            return 'Unknown';
                    }};

                CallLogService.list(1).then(
                    function(callLog) {
                        console.log(callLog);
                        $scope.data.lastCall = callLog[0];
                    },
                    function(error) {
                        console.error(error);
                    });
            }]);

     app.factory('CallLogService', ['$q', function($q) {
            return {
                list : function(days) {
                    var q = $q.defer();
                    // days is how many days back to go
                    window.plugins.calllog.list(days, function (response) {
                        q.resolve(response.rows);
                    }, function (error) {
                        q.reject(error)
                    });
                    return q.promise;
                },

                contact : function(phoneNumber) {
                    var q = $q.defer();
                    window.plugins.calllog.contact(phoneNumber, function (response) {
                        q.resolve(response);
                    }, function (error) {
                        q.reject(error)
                    });
                    return q.promise;
                },

                show : function(phoneNumber) {
                    var q = $q.defer();
                    window.plugins.calllog.show(phoneNumber, function (response) {
                        q.resolve(response);
                    }, function (error) {
                        q.reject(error)
                    });
                    return q.promise;
                },

                delete : function(phoneNumber) {
                    var q = $q.defer();
                    window.plugins.calllog.delete(id, function (response) {
                        q.resolve(response);
                    }, function (error) {
                        q.reject(error)
                    });
                    return q.promise;
                }
            }
        }]);

3.This is my index.html.

<body ng-app="lmp">
        <div ng-controller="lmpctrl">

            <div class="row">
                <div class="col">Last Call</div>
            </div>
            <div class="row">
                <div class="col col-30 col-offset-10">Name</div>
                <div class="col">{{data.lastCall.cachedName}}</div>
            </div>
            <div class="row">
                <div class="col col-30 col-offset-10">Number</div>
                <div class="col">{{data.lastCall.number}}</div>
            </div>
            <div class="row">
                <div class="col col-30 col-offset-10">Type</div>
                <div class="col">{{callTypeDisplay(data.lastCall.type)}}</div>
            </div>
            <div class="row">
                <div class="col col-30 col-offset-10">Date</div>
                <div class="col">{{data.lastCall.date | date}}</div>
            </div>
            <div class="row">
                <div class="col col-30 col-offset-10">Duration</div>
                <div class="col">{{data.lastCall.duration}} seconds</div>
            </div>
            <div class="row">
                <div class="col col-30 col-offset-10">Acknowledged</div>
                <div class="col">{{(data.lastCall.new == 1 ? 'yes' : 'no')}}</div>
            </div>

        </div>
        <script src="js/angular.min.js"></script>
          <script src="js/app.js"></script>
        <script src="js/ng-cordova.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>

4.I added this following code in my config.xml
<feature name="CallLog">
                <param name="android-package" value="com.ubookr.plugins.CallLogPlugin"/>
            </feature>
Run Code Online (Sandbox Code Playgroud)

我错过了什么,或者我错了.有人可以帮助我.提前谢谢.

小智 3

看来这window.plugins是未定义的。为了避免这种情况,我要做的就是在DeviceReady事件上手动引导 AngularJS,而不是使用ng-app指令,如Cordova + Angularjs + Device Ready中所述

为此,请ng-app从元素中删除指令<body>,并将此 JavaScript 放在脚本顶部app.js

document.addEventListener('deviceready', function() {
    var body = document.querySelector('body');
    angular.bootstrap(body, ['lmp']);
}, false);
Run Code Online (Sandbox Code Playgroud)

这将等到设备准备好引导 Angular,确保所有设备服务在您使用它们之前都可用。