在ionic 1中的控制器内部使用cordova插件CallLog

时间:2018-06-29 11:35:30

标签: cordova ionic-framework plugins

我想在控制器中使用CallLog插件,并从控制器中调用getCallLog插件,因为我们打开应用程序并从移动设备获取呼叫历史记录并将其显示在屏幕上。现在,我在按钮的click事件之后调用此函数,但是当我尝试直接使用此插件时,它显示未定义CallLog。如何直接在控制器中使用它?

这是我的代码:

    app.controller('callCtrl', function ($scope) {
    var thisScope = $scope;
    thisScope.mobileNumbers = [];
    $scope.removeItem = function (index) {
      $scope.mobileNumbers.splice(index, 1);
    };
    $scope.message = function () {
      var d = new Date();
      d.setHours(d.getHours() - 12);
      var filtersToday = [{
        "name": "date",
        "value": d.getTime(),
        "operator": ">=",
      }];
      window.plugins.callLog.requestReadPermission();
      window.plugins.callLog.getCallLog(filtersToday, function (data) {
        thisScope.mobileNumbers = data;
      }, function () {
        console.log("error 1", data);

      });

    }

  });

index.html:-

    <ion-content ng-controller="callCtrl">
      <button ion-button ng-click="message()">Default</button>
      <ion-list>
        <ion-item ng-repeat="d in mobileNumbers ">
               <h3>Number: {{d.number}}</h3>
               <h3>Name: {{d.name}}</h3>
               <h3>Duration: {{d.duration}}</h3>
               <h3>Type: {{d.type}}</h3>
               <h3>Phone Id: {{d.phoneAccountId}}</h3>
               <ion-option-button class="button-assertive ion-trash-a" ng-click="remove($index)"></ion-option-button>
        </ion-item>
    </ion-list>

0 个答案:

没有答案