gpt4 book ai didi

angularjs - $cordovaSQLite.execute 不是 ionic 中的函数

转载 作者:行者123 更新时间:2023-12-03 07:00:26 25 4
gpt4 key购买 nike

在我的代码中 $cordovaSQLite.execute 函数在 .run 函数中运行良好,但在我的 Controller 中出现错误。我不知道我做错了什么,我已经包含了所有必需的插件并按照这个非常好的示例的步骤进行操作 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.

最佳答案

看起来 myapp.controller(...) 调用中的代码是在启动时执行的。如果 Controller 连接到页面主体之类的东西,它还必须等待 Ionic/ngCordova 准备好(例如使用 $ionicPlatform.ready(...))。

关于angularjs - $cordovaSQLite.execute 不是 ionic 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33141209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com