I am trying to get values from Pre-Filled database Using ionic, but i keep getting this error:
TypeError: Cannot read property ‘transaction’ of null
I am running this app on device…
ionicApp = angular.module('starter', ['ionic', 'ngCordova']);
ionicApp.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
window.plugins.sqlDB.remove("populated.db",false,false);
window.plugins.sqlDB.copy("populated.db", function() {
db = $cordovaSQLite.openDB("populated.db");
}, function(error) {
console.error("Error Code -----------> " + JSON.stringify(error));
});
});
});
Controller
ionicApp.controller('ExampleController', function($scope,MyService,$ionicPlatform) {
$ionicPlatform.ready(function() {
$scope.categories = MyService.getCategories();
})
})
MyService
ionicApp.service('MyService', function($cordovaSQLite) {
this.getCategories = function() {
var output = [];
query = "SELECT * FROM categories";
$cordovaSQLite.execute(db, query).then(function(res) {
for (var i = 0; i < res.rows.length; i++) {
output.push(res.rows.item(i));
}
},function (err) {
console.error(err);
});
return output;
}
index.html
<ul class="list">
<li class="item" ng-repeat="category in categories">{{category.name}}</li>
</ul>