Answer the question
In order to leave comments, you need to log in
Why is .then not a function?
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;
})
})
})
}
});
})
.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;
}
}
})
Answer the question
In order to leave comments, you need to log in
populateData returns a normal array
A .then() is usually a method on an object of type promise
In this case, it is not necessary and the code should be replaced with
EventService.populateData(result).then(function(items) {
$scope.items = items
})
$scope.items = EventService.populateData(result)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question