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

How Do I Use Deviceready in A function on a Controller with $cordovaSQLite

$
0
0

@Harilall wrote:

Guys how do I use the deviceready function in a controller to get access to my SQLite database. I keep getting the error cannot read property null of undefined, here's my code

$ionicPlatform.ready(function(){
		document.addEventListener('deviceready', function(){
			db = $cordovaSQLite.openDB({name: "expenseApp.db"});

					var query = "insert into expenses (date, detail, amount) values(?,?,?)";
					$cordovaSQLite.execute(db, query, [dateInDb, expenseItem.detail, expenseItem.amount])
					.then(function(res){
						console.log("then function hit" + res);
						if (res.rows.length > 0)
						{
							var iAlert = $ionicPopup.alert({
								title: 'Item added to database',
								template: 'expenseItem.date = ' + expenseItem.date + '<br/>' + 'expenseItem.detail = ' + expenseItem.detail + '<br/>' +
											'expenseItem.amount = ' + expenseItem.amount,
							});
						}
					}), function(error){
						$ionicPopup.alert({
							title: 'Error',
							template: 'Something went wrong <br/>' + error.message
						});
					}

				});
			});

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>