Please I am new to angularjs and I got this code online to use in creating 
a call history/log app but it seems not to be working. Am I doing anything 
wrong with the code? 

app.js
angular.module('myApp',['ionic']).config(['$controllerProvider', function(
$controllerProvider) {
    $controllerProvider.allowGlobals();
}])
.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;
        }
    };
}])
.controller('DebugCtrl', ['$scope', 'CallLogService', 'LocalStorage',
    function ($scope, CallLogService, LocalStorage) {

        $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);
            });
    }])
.config(function($provide) {
$provide.decorator('CallLogService', ['$delegate', '$q', function ($delegate
, $q) {
  if (window.plugins && window.plugins.calllog) {
    return $delegate;
} else {
    return {
      list : function() {
        var lastCall = {
          cachedName: 'Joe Blow',
          cachedNumberType: 2,
          date: 1406720317112,
          duration: 2224,
          new: 1,
          number: '0420884679',
          type: 1
        };
        return $q.when([lastCall]);
      },
      contact : function() {
        return $q.when({});
      },
      show : function() {
        return $q.when(true);
      }
    };
  }
}]);
});
Enter code here...

index.html
<html ng-app="myApp">
<head>
<title> Blablabla</title>
<script src=""></script>
<script src="app.js"></script>
</head>
<body>
<ion-view class="h6" title="Debug">
    <ion-content class="has-header">
        <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>
    </ion-content>
</ion-view>
</body>
</html>



I appreciate

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to