I am trying to load some data from a cordovaSQLite database before loading my state/view. Naturally I’m trying to do it in the ‘resolve’ parameter in my state definition.
I have made a test that resolves a normal http call fine, but the sqllite call results in an infinte digest loop every way round I try it.
Is this a bug in cordova SQLlite or am I going about this the wrong way?
thanksindent preformatted text by 4 spaces
state:
.state("menu", {
templateUrl: "templates/menu.html",
controller: "MenuCtrl",
// ":id" is a path parameter.
url: "/menu",
resolve:{
simpleObj: function(){
return {value: 'simple!'};
},
httpTest: function($http){
return $http({method: 'GET', url: 'http://google.com'})
.then (function (data) {
return data;
});
},
sqliteTest: function(){
var deferred = $q.defer();
query = "SELECT * FROM reports";
$cordovaSQLite.execute(db, query, []).then(function(res) {
deferred.resolve(res);
}, function (err) {
console.log('error');
deferred.reject(err);
});
return deferred.promise;
}
}
})
controller:
angular.module('starter.controllers').controller('MenuCtrl', function($scope, simpleObj, promiseObj, sqliteTest) {
//here the promise get available
$scope.simpleObj = simpleObj;
console.log(JSON.stringify($scope.simpleObj));
$scope.promiseObj = promiseObj;
console.log(JSON.stringify($scope.promiseObj));
$scope.sqliteTest = sqliteTest;
$scope.sqliteTest.then(function(res) {
console.log(555555555555555555555555554345346);
for (var i = 0; i < res.rows.length; i++) {
console.log(res.rows.item(i).id);
}
}, function() {
console.log(2222222232323);
});
});