.controller("testCtrl",function($scope){
$scope.test = "123";
var dbSize = 5 * 1024 * 1024; // 5MB
//create db
var db = openDatabase("Products", "", "Product Cart", dbSize, function() {
console.log('db successfully opened or created');
});
db.transaction(function (tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS product(ID INTEGER PRIMARY KEY ASC, productName TEXT, price TEXT , imgPath TEXT, isCart BIT)");
tx.executeSql("INSERT INTO product(productName, price, imgPath, isCart) VALUES (?,?,?,?)",['testP','100','imgp','1']);
$scope.testClick = function(){
tx.executeSql('SELECT productName FROM product', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
console.log(results.rows.item(i).text);
}
});
}
});
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content ng-controller="testCtrl">
{{test}}
<button class="button" ng-click="testClick()">click</button>
</ion-content>
</ion-pane>
</body>
</html>
这里我附上了我的控制器代码和HTML代码。当我点击按钮时出现此错误“无法在'SQLTransaction'上执行'executeSql':不允许执行SQL。”。我怎样才能解决这个问题?谢谢