Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49229

Code Not Being Executed

$
0
0

@Harilall wrote:

I was having problems with the SQLite database but managed to solve that error by placing the code within a deviceready listener function, the problem now is although I don't get the same prior errors my code in the deviceready function isn't getting hit. I have tried debugging in Chrome and it just skips over the code - please advise, here's my function code below

$scope.saveExpense = function(expenseItem){
		if(angular.isDefined(expenseItem) && angular.isDefined(expenseItem.detail) && angular.isDefined(expenseItem.amount))
		{
			var dateInDb = $filter('date')(expenseItem.myDate, 'yyyy-MM-dd');

				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("res = " + 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
						});
					}

				});

			$state.reload();
		}
	}

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 49229

Trending Articles



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