Websql with select sql


#1

Hi Team,

I am suffering with a issue in websql, this is example of code “controller.js”

$scope.totalamts = function() {
			var tamounts;
			 db.transaction(function (tx) {
				tx.executeSql("SELECT SUM(totalamt) as tas FROM TempCart", [], function(tx, results) {
					if(results.rows.length > 0) {
						for(var i = 0; i < results.rows.length; i++) {
							/* tamount[] = results.rows.item(i).tas */
							/* console.log("R<img src="/uploads/default/original/2X/c/c8dbd14ac6d2084f3564362ae3d2735e3a412b02.png" width="690" height="388"> esult -> " + results.rows.item(i).tas ); */
						}
						tamounts = results.rows.item(0).tas
						console.log(tamounts);
					}
				});
			});
			return tamounts;
		}

I want to return amount in this function but console.log print value but function did not return the value can you please help me to solve this bug, I am just calling this function from menu page html code is “menu.html”

<div class="row">
					<div class="col ">
							<i class="fa fa-inr fa-lg p c txt_white" >{{totalamts()}}</span></i>
						</div>
						
						<div class="col">
							<i class="fa fa-shopping-cart fa-lg p c txt_white pull-right"><span>{{totalqtys()}}</span></i>
					</div>
				</div>

#2

hi,
Your console log is in the right place, the return didn’t.

Add a callback function to your method which receive 2 arguments (err, data) and call it just after the console statement passing null as err and tamounts as data