$ cordovaSQLite.execute不是离子

时间:2015-10-15 06:18:08

标签: angularjs ionic

在我的代码中 $ 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不是函数       在新的(app.js:105)       at Object.invoke(ionic.bundle.js:13277)       在extend.instance(ionic.bundle.js:17826)       at nodeLinkFn(ionic.bundle.js:16936)       在compositeLinkFn(ionic.bundle.js:16368)       在compositeLinkFn(ionic.bundle.js:16372)       at publicLinkFn(ionic.bundle.js:16243)       at ionic.bundle.js:10462       在Scope。$ eval(ionic.bundle.js:24673)       在Scope。$ apply(ionic.bundle.js:24772)(匿名函数)@ ionic.bundle.js:21157 console-via-logger.js:173否   找到Content-Security-Policy元标记。使用时请添加一个   cordova-plugin-whitelist插件。(匿名函数)@   console-via-logger.js:173 console-via-logger.js:173应用程序是   从后台console-via-logger.js恢复:173 OPEN数据库:   db_demoionic.db 2console-via-logger.js:173新事务正在等待   对于open operation console-via-logger.js:173成功   console-via-logger.js:173 DB已打开:db_demoionic.db   console-via-logger.js:173未找到结果console-via-logger.js:173   未找到Content-Security-Policy元标记。请在使用时添加一个   cordova-plugin-whitelist插件。 3console-via-logger.js:173没有   找到Content-Security-Policy元标记。使用时请添加一个   cordova-plugin-whitelist插件。

1 个答案:

答案 0 :(得分:0)

看起来TRANSFORM payfrequency([structurepayrollFrequency], Max([2015_PREMIUM]-[2015_EMPLOYER_CONTR])) AS 2015_EMPLOYEE_CONTR 调用中的代码在启动时执行。如果控制器连接到类似页面的东西,它也必须等到Ionic / ngCordova准备就绪(例如使用myapp.controller(...))。