我一直试图将sqlite纳入一个简单的离子应用程序,这是我一直以来的过程:
原文链接:https://www.f2er.com/angularjs/144336.htmlionic start myApp sidemenu
ionic plugin add https://github.com/brodysoft/Cordova-sqlitePlugin
和ngCordova
bower install ngCordova
这给了我以下选择:
无法找到合适的版本,请选择一个:
1)角度#1.2.0,解析为1.2.0,由ngCordova#0.1.4-alpha要求
2)角度#> = 1.0.8,其解析为1.2.0,并且角度-i-router#0.2.10需要
3)角度#1.2.25,解析为1.2.25,需要角动画#1.2.25角度消毒#1.2.25
4)角度#〜1.2.17,解析为1.2.25,由离子#1.0.0-beta.13Prefix选择!坚持到bower.json
我选择了选项3)
我将脚本包含在文件中,如下所示:
<script src="lib/ionic/js/ionic.bundle.js"></script> <script src="lib/ngCordova/dist/ng-cordova.js"></script> <script src="cordova.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script>
.controller('SearchCtrl',function ($scope,$cordovasqlite){ console.log('Test'); var db = $cordovasqlite.openDB({ name: "my.db" }); // for opening a background db: var db = $cordovasqlite.openDB({ name: "my.db",bgType: 1 }); $scope.execute = function() { console.log('Test'); var query = "INSERT INTO test_table (data,data_num) VALUES (?,?)"; $cordovasqlite.execute(db,query,["test",100]).then(function(res) { console.log("insertId: " + res.insertId); },function (err) { console.error(err); }); }; })
这导致错误:
> TypeError: Cannot read property 'openDatabase' of undefined > at Object.openDB (http://localhost:8100/lib/ngCordova/dist/ng-cordova.js:2467:36)
接下来我尝试手动包括sqlitePlugin.js:
从plugins / com.brodysoft.sqlitePlugin / www复制到main www /并将其添加到index.html页面
我尝试包括在一切之前:
<script src="sqlitePlugin.js"></script> <script src="lib/ionic/js/ionic.bundle.js"></script> <script src="lib/ngCordova/dist/ng-cordova.js"></script> <script src="cordova.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script>
我得到错误ReferenceError:cordova没有定义
所以我尝试把它包含在cordova.js脚本之后,但仍然得到相同的错误
真的很感激帮助
在相关的情况下,这些是目前使用的Cordova和离子版本:
ionic --version 1.2.5 cordova --version 3.5.0-0.2.7
这是生成的bower.json
{ "name": "myApp","private": "true","devDependencies": { "ionic": "driftyco/ionic-bower#1.0.0-beta.13" } }
和我的package.json:
{ "name": "myapp","version": "1.0.0","description": "myApp: An Ionic project","dependencies": { "gulp": "^3.5.6","gulp-sass": "^0.7.1","gulp-concat": "^2.2.0","gulp-minify-css": "^0.3.0","gulp-rename": "^1.2.0" },"devDependencies": { "bower": "^1.3.3","gulp-util": "^2.2.14","shelljs": "^0.3.0" } }