I'm new in AngularJS. I use WebSQL for database and i've some problem to operate my file. I've 2 javascript file named service.js
and controller.js
.
service.js :
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
db.transaction(function (tx) {
var sql = ('CREATE TABLE IF NOT EXISTS CART (id unique, name, price)');
});
function addToCart(id, name, price){
db.transaction(
function (tx) {
tx.executeSql(
"INSERT INTO CART (id, name, price) VALUES (NULL, ?, ?);",
[data.name,
data.price,
],
);
}
controller.js :
angular.module('login').controller('Controller',
['Service', '$scope','$state', '$webSql', function(Service, $scope,$state,$webSql) {
var self = this;
self.addToCart = addToCart;
self.database = Service.db;
function database(){
self.database = db;
return database;
}
function addToCart(id, name, price) {
alert("Success add to your cart" + id);
}
}
]);
How i can call my db from Service.js to Controller.js?