I have written a factory for getting data from local websql database.The code is as below:
app.factory('readData', function () {
var localData=[];
var data=[];
var db = openDatabase("here is ma database");
var selectAllStatement = "SELECT * FROM tablename";
db.transaction(function (tx) {
tx.executeSql(selectAllStatement, [], function (tx, result) {
dataset = result.rows;
for (var i = dataset.length - 1; i >= 0; i--) {
data[i]=dataset.item(i);
};
localData=data;
console.log(data);
return localData;
});
});
return localData ;});
This factory is used in a controller to get the data.The code is:
function tricoreContrller($scope, readData) {$scope.users = readData;console.log( $scope.users);}tricoreContrller($scope, readData);
I have used console.log to check whether the data is actually coming in factory.I get result in console from factory but not from controller.Plz tel me where i am going wrong.I have used LocalData as temperary variable to store the data from array "data".