Errors mit dem ngCordova $ cordovaSQLite Plugin mit Ionic
Ich versuche derzeit, das ngCordova SQLite-Plugin mit meiner App zu implementieren, muss aber noch eine funktionierende Lösung erstellen. Ich bin gefolgtNic Raboys Blogbeitrag zum Implementieren des SQLite-Plugins mit Ihrem Ionic-Projekt in ein "T", aber ich erhalte weiterhin die Fehlermeldung:Error: undefined ist kein Objekt (Auswertung von '$ window.sqlitePlugin.openDatabase') Wenn ich versuche, die Anwendung im iOS-Emulator auszuführen.
Ich habe auch überprüft, ob ngCordova und das Plugin in mein Projekt geladen wurden.
Dies ist die Reihenfolge, in der meine Skripte in mein Projekt geladen werden:
<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>
Mein Code ist unten.
app.js
angular.module('whoPaidLast', ['ionic', 'ngCordova', 'whoPaidLast.controllers', 'whoPaidLast.services'])
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB({ name: 'accounts.db' });
$cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS accounts (id integer primary key autoincrement, firstname text, lastname text, paid numeric, date text)');
});
})
controller.js
angular.module('whoPaidLast.controllers', [])
.controller('DashCtrl', ['$ionicPlatform', '$scope', '$ionicModal', '$ionicActionSheet', '$cordovaSQLite', function ($ionicPlatform, $scope, $ionicModal, $ionicActionSheet, $cordovaSQLite) {
$scope.getList = function() {
var query = 'SELECT id, firstname, lastname, paid, date FROM accounts ORDER BY lastname ASC';
var db = $cordovaSQLite.openDB({ name: 'accounts.db' });
$ionicPlatform.ready(function() {
$cordovaSQLite.execute(db, query, [id, firstname, lastname, paid, date]).then(function(result) {
if(result.rows.length > 0) {
console.log('rows =' + result.rows);
} else {
$scope.results = [];
}
}, function(error) {
console.error(err);
});
});
};
});
Jede Information oder Hilfe, die Sie möglicherweise haben, würde helfen. Vielen Dank im Voraus.