1
我已經安裝使用這個指令sqlite的科爾多瓦插件如下: http://ngcordova.com/docs/plugins/sqlite/
請看下面的控制器代碼:
.controller('PlaylistsCtrl', function ($scope, $cordovaSQLite) {
$scope.playlists = [
{ title: 'Reggae', id: 1 },
{ title: 'Chill', id: 2 },
{ title: 'Dubstep', id: 3 },
{ title: 'Indie', id: 4 },
{ title: 'Rap', id: 5 },
{ title: 'Cowbell', id: 6 }
];
//var db = $cordovaSQLite.openDB({ name: "my.db" });
//// for opening a background db:
//var db = $cordovaSQLite.openDB({ name: "my.db", bgType: 1 });
//$scope.execute = function() {
// 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);
// });
//};
})
錯誤:
您注射了ngCordova嗎?例如'angular.module('starter.controllers',['ngCordova'])' – Huey
謝謝。這是問題!我已經提到https://www.thepolyglotdeveloper.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/ –