在我的代碼$ cordovaSQLite.execute功能工作良好.run功能,但給我錯誤在我的控制器。我不知道我做錯了,我已經包括了所有必需的插件,然後按照這個很好的例子 https://blog.nraboy.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/
var db = null;
var myapp=angular.module('starter', ['ionic','btford.socket-io','LoginCntrl','SlideCntrl','app','ChatCntrl','ngCordova','ngCordova.plugins.sqlite'])
.run(function($ionicPlatform,$cordovaSQLite) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
console.log("The application is resuming from the background");
db = $cordovaSQLite.openDB({ name: App_DB_Name });
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
var query = "SELECT firstname, lastname FROM people WHERE lastname = ?";
$cordovaSQLite.execute(db, query, ["pruthvi"]).then(function(result) {
if(result.rows.length > 0) {
console.log("SELECTED -> " + result.rows.item(0).firstname + " " + result.rows.item(0).lastname);
alert("SELECTED -> "+ result.rows.item(0).firstname + " " + result.rows.item(0).lastname)
} else {
console.log("No results found");
}
}, function (err) {
console.error(err);
});
// $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS "+ App_DB_Table_Login_Name +"(id integer primary key, login_username text, login_password text)");
console.log("success");
});
});
myapp.controller('IndexController', ['$scope','$rootScope', function($scope,$rootScope,$cordovaSQLite, $ionicPlatform){
var query = "SELECT firstname, lastname FROM people WHERE lastname = ?";
$cordovaSQLite.execute(db, query, ["pruthvi"]).then(function(result) {
if(result.rows.length > 0) {
console.log("SELECTED -> " + result.rows.item(0).firstname + " " + result.rows.item(0).lastname);
alert("SELECTED -> "+ result.rows.item(0).firstname + " " + result.rows.item(0).lastname)
} else {
console.log("No results found");
}
}, function (err) {
console.error(err);
});
}]);
TypeError: $cordovaSQLite.execute is not a function at new (app.js:105) at Object.invoke (ionic.bundle.js:13277) at extend.instance (ionic.bundle.js:17826) at nodeLinkFn (ionic.bundle.js:16936) at compositeLinkFn (ionic.bundle.js:16368) at compositeLinkFn (ionic.bundle.js:16372) at publicLinkFn (ionic.bundle.js:16243) at ionic.bundle.js:10462 at Scope.$eval (ionic.bundle.js:24673) at Scope.$apply (ionic.bundle.js:24772)(anonymous function) @ ionic.bundle.js:21157 console-via-logger.js:173 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.(anonymous function) @ console-via-logger.js:173 console-via-logger.js:173 The application is resuming from the background console-via-logger.js:173 OPEN database: db_demoionic.db 2console-via-logger.js:173 new transaction is waiting for open operation console-via-logger.js:173 success console-via-logger.js:173 DB opened: db_demoionic.db console-via-logger.js:173 No results found console-via-logger.js:173 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin. 3console-via-logger.js:173 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.