service.js
.factory('EventService', function ($http, $cordovaSQLite) { return { //some code here.. populateData: function (data) { var items = []; for (i = 0; i < data.length; i++) { items.push(data[i]); } return items; } } })
controller.js
.controller('NearCtrl', function ($scope, $http, $cordovaSQLite, EventService) { EventService.getDataFromDB().then(function (result) { if (result.length > 0) { EventService.populateData(result).then(function (items) { $scope.items = items; }) } else { EventService.getDataFromApi().then(function () { EventService.getDataFromDB().then(function (result) { EventService.populateData(result).then(function (items) { $scope.items = items; }) }) }) } }); })
When I’m trying to run this code, I get “TypeError: EventService.populateData(…).then is not a function”.
What am I doing wrong?