@praveenjp wrote:
In my ionic app. I created a service named webservice to retrieve data from sqlite database using angularjs.It selecting data properly and get result in console it works fine, but it return
undefined
always.This is my sample code.
app.factory('webservice',function($http,$cordovaSQLite,$q){ var obj = {}; obj.getNote = function(){ var query = "SELECT subject, note FROM notes"; var q = $q.defer(); $cordovaSQLite.execute(db, query).then(function(res) { if(res.rows.length > 0) { var data = res.rows; console.log(data); //Result - Working.. q.resolve(res.rows); //Result - Undefined.. return data; //Result - Undefined.. } else { console.log("No results found"); return false; } }, function (err) { console.error(err); }); } return obj; });
This is my controller:
app.controller('noteCtrl', function($scope,$state,webservice){ $scope.getNote = function(){ console.log(webservice.getNote()); // Undefined. } });
I hope angular experts will be there.
So please try to find out good solution for me.
Thank You!
Posts: 1
Participants: 1