Last active
October 28, 2015 13:43
-
-
Save tarekeldeeb/975cbe0fc85239766e9f to your computer and use it in GitHub Desktop.
Followed: https://gist.github.com/borissondagh/29d1ed19d0df6051c56f but got chrome error: `Exception in onResRdy: TypeError: Cannot read property 'htmlRes' of undefined`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db = null; | |
angular.module('starter', ['ionic', 'myapp.controllers', 'myapp.services', 'ngCordova']) | |
.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) { | |
// org.apache.cordova.statusbar required | |
StatusBar.styleDefault(); | |
} | |
if(window.cordova) { | |
// App syntax | |
db = $cordovaSQLite.openDB("myapp.db"); | |
} else { | |
// Ionic serve syntax | |
db = window.openDatabase("myapp.db", "1.0", "My app", -1); | |
} | |
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS team (id integer primary key, name text)"); | |
}); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myapp.controllers', []) | |
.controller('TeamCtrl', function($scope, Team) { | |
$scope.team = []; | |
$scope.team = null; | |
$scope.updateTeam = function() { | |
Team.all().then(function(team){ | |
$scope.team = team; | |
}); | |
} | |
$scope.updateTeam(); | |
$scope.createNewTeamMember = function(member) { | |
Team.add(member); | |
$scope.updateTeam(); | |
}; | |
$scope.removeMember = function(member) { | |
Team.remove(member); | |
$scope.updateTeam(); | |
}; | |
$scope.editMember = function(origMember, editMember) { | |
Team.update(origMember, editMember); | |
$scope.updateTeam(); | |
}; | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> | |
<title></title> | |
<link href="lib/ionic/css/ionic.css" rel="stylesheet"> | |
<link href="css/style.css" rel="stylesheet"> | |
<script src="lib/ionic/js/ionic.bundle.js"></script> | |
<script src="js/ng-cordova.min.js"></script> | |
<script src="cordova.js"></script> | |
<script src="js/app.js"></script> | |
<script src="js/services.js"></script> | |
<script src="js/controllers.js"></script> | |
</head> | |
<body ng-app="starter"> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myapp.services', []) | |
.factory('DBA', function($cordovaSQLite, $q, $ionicPlatform) { | |
var self = this; | |
// Handle query's and potential errors | |
self.query = function (query, parameters) { | |
parameters = parameters || []; | |
var q = $q.defer(); | |
$ionicPlatform.ready(function () { | |
$cordovaSQLite.execute(db, query, parameters) | |
.then(function (result) { | |
q.resolve(result); | |
}, function (error) { | |
console.warn('I found an error'); | |
console.warn(error); | |
q.reject(error); | |
}); | |
}); | |
return q.promise; | |
} | |
// Proces a result set | |
self.getAll = function(result) { | |
var output = []; | |
for (var i = 0; i < result.rows.length; i++) { | |
output.push(result.rows.item(i)); | |
} | |
return output; | |
} | |
// Proces a single result | |
self.getById = function(result) { | |
var output = null; | |
output = angular.copy(result.rows.item(0)); | |
return output; | |
} | |
return self; | |
}) | |
.factory('Team', function($cordovaSQLite, DBA) { | |
var self = this; | |
self.all = function() { | |
return DBA.query("SELECT id, name FROM team") | |
.then(function(result){ | |
return DBA.getAll(result); | |
}); | |
} | |
self.get = function(memberId) { | |
var parameters = [memberId]; | |
return DBA.query("SELECT id, name FROM team WHERE id = (?)", parameters) | |
.then(function(result) { | |
return DBA.getById(result); | |
}); | |
} | |
self.add = function(member) { | |
var parameters = [member.id, member.name]; | |
return DBA.query("INSERT INTO team (id, name) VALUES (?,?)", parameters); | |
} | |
self.remove = function(member) { | |
var parameters = [member.id]; | |
return DBA.query("DELETE FROM team WHERE id = (?)", parameters); | |
} | |
self.update = function(origMember, editMember) { | |
var parameters = [editMember.id, editMember.name, origMember.id]; | |
return DBA.query("UPDATE team SET id = (?), name = (?) WHERE id = (?)", parameters); | |
} | |
return self; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment