jeudi 26 février 2015

List and detail item ionic

I have a problem , I can not load the data of the item called because the database queries defined in services.js runs after and so my array is empty when called by $ brooms , someone has a solution I have to run the query inside the controller itself?


thanks in advance



controller('SchedaProdottoCtrl', function(ProductService, $cordovaSQLite, $scope,$stateParams, $ionicLoading, $ionicActionSheet, $ionicListDelegate, GetTodayDate) {

$scope.items = ProductService.get($stateParams.productID);

});


And in the services.js have:



.factory('ProductService', function($cordovaSQLite) {

var items = [];
$cordovaSQLite.execute(db, "SELECT * FROM prodotti").then(function(res) {
if (res.rows.length) {
for (var i = 0; i < res.rows.length; i++) {
var row = res.rows.item(i);
items.push({
IdProdotti:row.idProdotti,
nomeProdotto:row.Nome,
dataScadenza:row.DataScadenza
});
}
} else {
console.log('No result found');
return false;
}
});


return {
all: function() {
return items;
},
get: function(productID) {
// Simple index lookup
return items[productID];
}
}
})

Aucun commentaire:

Enregistrer un commentaire