Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

Sqlite - Unable to return selected data angularjs service

$
0
0

@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. :frowning:

Thank You!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>