1. <small id='wvvBc'></small><noframes id='wvvBc'>

    2. <i id='wvvBc'><tr id='wvvBc'><dt id='wvvBc'><q id='wvvBc'><span id='wvvBc'><b id='wvvBc'><form id='wvvBc'><ins id='wvvBc'></ins><ul id='wvvBc'></ul><sub id='wvvBc'></sub></form><legend id='wvvBc'></legend><bdo id='wvvBc'><pre id='wvvBc'><center id='wvvBc'></center></pre></bdo></b><th id='wvvBc'></th></span></q></dt></tr></i><div id='wvvBc'><tfoot id='wvvBc'></tfoot><dl id='wvvBc'><fieldset id='wvvBc'></fieldset></dl></div>
      <legend id='wvvBc'><style id='wvvBc'><dir id='wvvBc'><q id='wvvBc'></q></dir></style></legend>
        <bdo id='wvvBc'></bdo><ul id='wvvBc'></ul>

      <tfoot id='wvvBc'></tfoot>

    3. 如何在 Ionic 框架中使用 ngCordova s​​qlite 服务和

      时间:2023-06-06

      <i id='9OaYV'><tr id='9OaYV'><dt id='9OaYV'><q id='9OaYV'><span id='9OaYV'><b id='9OaYV'><form id='9OaYV'><ins id='9OaYV'></ins><ul id='9OaYV'></ul><sub id='9OaYV'></sub></form><legend id='9OaYV'></legend><bdo id='9OaYV'><pre id='9OaYV'><center id='9OaYV'></center></pre></bdo></b><th id='9OaYV'></th></span></q></dt></tr></i><div id='9OaYV'><tfoot id='9OaYV'></tfoot><dl id='9OaYV'><fieldset id='9OaYV'></fieldset></dl></div>
        <bdo id='9OaYV'></bdo><ul id='9OaYV'></ul>
        <tfoot id='9OaYV'></tfoot>

          <small id='9OaYV'></small><noframes id='9OaYV'>

          1. <legend id='9OaYV'><style id='9OaYV'><dir id='9OaYV'><q id='9OaYV'></q></dir></style></legend>

                  <tbody id='9OaYV'></tbody>
              • 本文介绍了如何在 Ionic 框架中使用 ngCordova s​​qlite 服务和 Cordova-SQLitePlugin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我一直在尝试将 sqlite 合并到一个简单的 Ionic 应用程序中,这是我一直遵循的过程:

                I have been trying to incorperate sqlite into a simple Ionic app and this is the process I have been following:

                 ionic start myApp sidemenu
                

                然后我安装sqlite插件:

                Then I install the sqlite plugin:

                ionic plugin add https://github.com/brodysoft/Cordova-SQLitePlugin
                

                和 ngCordova

                and ngCordova

                bower install ngCordova
                

                这给了我以下选项:无法找到适合 angular 的版本,请选择一个:1) angular#1.2.0 解析为 1.2.0 并且 ngCordova#0.1.4-alpha 需要2) angular#>= 1.0.8 解析为 1.2.0 并且 angular-ui-router#0.2.10 需要3) angular#1.2.25 解析为 1.2.25 并且是 angular-animate#1.2.25、angular-sanitize#1.2.25 所需要的4) angular#~1.2.17 解析为 1.2.25 并且是 ionic#1.0.0-beta.13 需要的前缀选择!将其持久化到 bower.json

                this gave me the following options: Unable to find a suitable version for angular, please choose one: 1) angular#1.2.0 which resolved to 1.2.0 and is required by ngCordova#0.1.4-alpha 2) angular#>= 1.0.8 which resolved to 1.2.0 and is required by angular-ui-router#0.2.10 3) angular#1.2.25 which resolved to 1.2.25 and is required by angular-animate#1.2.25, angular-sanitize#1.2.25 4) angular#~1.2.17 which resolved to 1.2.25 and is required by ionic#1.0.0-beta.13Prefix the choice with ! to persist it to bower.json

                我选择了选项 3)我将脚本包含在文件中,如下所示:

                I picked option 3) and I included the scripts in the file as follows:

                <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>
                

                然后我在搜索视图中添加了一个控制器:

                I then added a controller to the search view:

                .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 复制到主 www/ 并将其添加到索引中.html页面

                Next I tried manually including the SQLitePlugin.js by: copying from plugins/com.brodysoft.sqlitePlugin/www to main www/ and adding it to the index.html page

                我尝试在一切之前包括:

                I tried including before everything:

                 <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脚本之后包含它,但仍然得到相同的错误

                I get Error ReferenceError: cordova is not defined so I then tried including it after the cordova.js script but still get the same error

                非常感谢您的帮助如果相关,这些是我正在使用的 Cordova 和 ionic 的当前版本:

                would really appreciate the help in case it is relevant, these are the current versions of Cordova and ionic I am using:

                ionic --version  1.2.5
                cordova --version 3.5.0-0.2.7
                

                这是生成的 bower.json

                and this is the generated bower.json

                {
                  "name": "myApp",
                  "private": "true",
                  "devDependencies": {
                    "ionic": "driftyco/ionic-bower#1.0.0-beta.13"
                  }
                }
                

                和我的 package.json:

                and my 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"
                  }
                }
                

                推荐答案

                如果有人尝试在浏览器中运行它时仍然出现错误,请尝试以下方法:

                If someone still got an error when trying to run it in a browser, try this one:

                if (window.cordova) {
                      db = $cordovaSQLite.openDB({ name: "my.db" }); //device
                    }else{
                      db = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100); // browser
                    }
                

                这篇关于如何在 Ionic 框架中使用 ngCordova s​​qlite 服务和 Cordova-SQLitePlugin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:无法格式化默认的 MySQL 日期时间 下一篇:如何使用 MEAN 堆栈(MySQL、Express、Angular、Node)将数

                相关文章

                最新文章

              • <tfoot id='TVoOP'></tfoot>

                  <legend id='TVoOP'><style id='TVoOP'><dir id='TVoOP'><q id='TVoOP'></q></dir></style></legend>

                  <small id='TVoOP'></small><noframes id='TVoOP'>

                  • <bdo id='TVoOP'></bdo><ul id='TVoOP'></ul>

                    <i id='TVoOP'><tr id='TVoOP'><dt id='TVoOP'><q id='TVoOP'><span id='TVoOP'><b id='TVoOP'><form id='TVoOP'><ins id='TVoOP'></ins><ul id='TVoOP'></ul><sub id='TVoOP'></sub></form><legend id='TVoOP'></legend><bdo id='TVoOP'><pre id='TVoOP'><center id='TVoOP'></center></pre></bdo></b><th id='TVoOP'></th></span></q></dt></tr></i><div id='TVoOP'><tfoot id='TVoOP'></tfoot><dl id='TVoOP'><fieldset id='TVoOP'></fieldset></dl></div>