SlideShare uma empresa Scribd logo
1 de 32
1
Creating a CRUD with Ionic – Part 1
Juliano Marcos Martins – juliano.jmm@gmail.com
http://jmmwrite.wordpress.com
2
SQLite
Is a software library that
implements a self-contained,
serverless, zero-configuration,
transactional SQL database
engine.
https://www.sqlite.org/
3
Local Storage
Can be used to store data, but
don't Assume that it will Always
Work In Your Hybrid App.
// example
localStorage.setItem('nome', 'Juliano');
var name = localStorage.getItem('nome');
console.log(name);
IOs and Android can clean it in
some situations.
4
Intro
We will create an application to
manage people from a table.
Its recommended that you already have basic concepts about Ionic and Mobile Development
before go ahead. For more intro material, check my blog:
http://jmmwrite.wordpress.com/
You can get the source code from this slides here →
https://github.com/julianommartins/ionicDataBase.git
5
Step by Step
● Create the project
ionic start ionicDataBase blank
6
Step by Step
● Enter in the project folder and Add platform:
ionic platform add android
7
Step by Step
● Add SQLite module (documentation: http://ngcordova.com/docs/plugins/sqlite/ ):
cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git
8
Step by Step
● Go to http://ngcordova.com/docs/install/ and get the JS lib (download the zip file)
● Extract it and get ng-cordova.min.js , put this file in the JS folder of your application
* You can also use bower to get ng-cordova
9
Step by Step
● Open your index.html file and import ng-cordova there by adding the folowing line
BEFORE cordova import:
<script src="js/ng-cordova.min.js"></script>:
10
Step by Step
● Open your app.js file and inject ngCordova module:
This will make module work!
11
Step by Step – index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DB Example</title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Pessoas</h1>
</ion-header-bar>
<ion-content ng-controller="DBController">
<button class="button" ng-click="insert('Juliano','Martins')">Insert</button>
<button class="button" ng-click="select('Martins')">Select</button>
Resultado: {{mensagemFinal}}
Resultado: {{resultado}}
</ion-content>
</ion-pane>
</body>
</html>
12
Step by Step – app.js
// Database instance.
var db = null;
// Include dependency: ngCordova
var starter = angular.module('starter', ['ionic', '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) {
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB({name: "my.db"});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS pessoas (id INTEGER PRIMARY KEY, firstname text, lastname text)");
});
})
starter.controller('DBController', function($scope, $cordovaSQLite) {
$scope.resultado = [];
$scope.mensagemFinal = "Iniciou Sistema";
$scope.insert = function(firstname, lastname) {
var query = "insert into pessoas (firstname, lastname) values (?,?)";
$cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) {
$scope.mensagemFinal = "FOI";
$scope.resultado.push({mensagem: "Insert Ok"});
console.log("Insert ID -> " + result.insertId);
}, function(error){
$scope.resultado.push({mensagem: "insert Fail"});
$scope.mensagemFinal = "Fail";
console.log(error);
});
}
13
Step by Step – app.js - continuation
$scope.select = function(lastname){
var query = "select firstname, lastname from pessoas where lastname = ?";
$cordovaSQLite.execute(db,query,[lastname]).then(function(result) {
if(result.rows.length > 0){
$scope.mensagemFinal = "ACHEI";
$scope.resultado = result.rows.item(0).firstname;
console.log("Achei " + result.rows.item(0).firstname + " " + result.rows.item(0).lastname);
} else {
$scope.mensagemFinal = "NAO ACHEI";
$scope.resultado = [];
console.log("Nao achei");
}
}, function(error){
console.log(error);
});
}
});
14
Step by Step
● Let's run with the command (you need to have an emulator or your physical phone
connected, in my case, I have Genymotion running):
ionic run android
15
TIP
● To see the Android log, go to the folder platform-tools from your sdk and run:
./adb logcat
● This is for Linux.
16
Creating a CRUD with Ionic – Part 2
Juliano Marcos Martins – juliano.jmm@gmail.com
http://jmmwrite.wordpress.com
17
Part 2
● We have created a code that insert and search for names, but, its hardcoded!
● Now we will create a FORM, to allow user type First and Last names and perform the
Insert and Search Operations with this data.
● We are not wondering about form validation for now, but, we will create a better UI at
least!
You can get the source code from this slides here →
https://github.com/julianommartins/ionicDataBase.git
18
Step by Step – index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DB Example</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>
</head>
<body ng-app="starter">
<ion-pane ng-controller="DBController">
<ion-header-bar class="bar-positive">
<h1 class="title">Pessoas</h1>
</ion-header-bar>
<ion-content>
<div class="list">
<label class="item item-input item-floating-label">
<span class="input-label">First Name</span>
<input type="text" placeholder="First Name" data-ng-model="fsName">
</label>
<label class="item item-input item-floating-label">
<span class="input-label">Last Name</span>
<input type="text" placeholder="Last Name" data-ng-model="lstName">
</label>
<button class="button button-balanced" ng-click="select(lstName)">Select</button>
<button class="button button-positive" ng-click="insert(fsName,lstName)">Insert</button>
<button class="button button-energized" ng-click="delete(lstName)">Delete</button>
<button class="button button-assertive" ng-click="update(fsName,lstName)">Update</button>
<label class="item item-input">
<input type="text" readonly value="{{resultado}}">
</label>
</div>
</ion-content>
<ion-footer-bar class="bar-positive">
<h1 class="title">Pessoas</h1>
</ion-footer-bar>
</ion-pane>
</body>
</html>
19
Step by Step – app.js
// Database instance.
var db = null;
// Include dependency: ngCordova
var starter = angular.module('starter', ['ionic', '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) {
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB({name: "my.db"});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS pessoas (id INTEGER PRIMARY KEY, firstname text, lastname text)");
});
})
starter.controller('DBController', function($scope, $cordovaSQLite) {
$scope.resultado = "";
$scope.insert = function(firstname, lastname) {
var query = "insert into pessoas (firstname, lastname) values (?,?)";
$cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) {
//$scope.resultado.push({mensagem: "Insert Ok"});
$scope.resultado = "Insert Ok";
}, function(error){
$scope.resultado = "Insert FAIL";
});
}
20
Step by Step – app.js (continuation)
$scope.select = function(lastname){
var query = "select firstname, lastname from pessoas where lastname = ?";
$cordovaSQLite.execute(db,query,[lastname]).then(function(result) {
if(result.rows.length > 0){
$scope.resultado = result.rows.item(0).firstname + " found with this last name.";
} else {
$scope.resultado = "Not found";
}
}, function(error){
console.log(error);
});
}
});
21
Step by Step
● Let's run with the command (you need to have an emulator or your physical phone
connected, in my case, I have Genymotion running):
ionic run android
22
Part 3
● Now, lets implement the update and delete operations.
You can get the source code from this slides here →
https://github.com/julianommartins/ionicDataBase.git
23
Step by Step – app.js
$scope.delete = function(lastname) {
var query = "delete from pessoas where lastname = ?";
$cordovaSQLite.execute(db,query,[lastname]).then(function(result) {
$scope.resultado = "Delete Ok.";
}, function(error){
$scope.resultado = "Delete FAIL!";
});
}
$scope.update = function(firstname, lastname) {
var query = "update pessoas set firstname = ? where lastname = ?";
$cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) {
$scope.resultado = "Update OK.";
}, function(error){
$scope.resultado = "Update FAIL!";
});
}
Just add this functions to app.js
24
Part 4
● We have a Functional Crud, but now, we want a function to list all the people from DB!
● Also, we will remove the delete button and put it in the list, to let user swipe the user in
order to remove.
You can get the source code from this slides here →
https://github.com/julianommartins/ionicDataBase.git
25
Step by Step – index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DB Example</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>
</head>
<body ng-app="starter">
<ion-pane ng-controller="DBController">
<ion-header-bar class="bar-positive">
<h1 class="title">People List</h1>
</ion-header-bar>
<ion-content>
<label class="item item-input item-floating-label">
<span class="input-label">First Name</span>
<input type="text" placeholder="First Name" data-ng-model="fsName">
</label>
<label class="item item-input item-floating-label">
<span class="input-label">Last Name</span>
<input type="text" placeholder="Last Name" data-ng-model="lstName">
</label>
<button class="button button-balanced" ng-click="select(lstName)">Select</button>
<button class="button button-positive" ng-click="insert(fsName,lstName)">Insert</button>
<button class="button button-energized" ng-click="update(fsName,lstName)">Update</button>
<button class="button button-royal" ng-click="selectAll()">List</button>
<label class="item item-input">
<input type="text" readonly value="{{resultado}}">
</label>
<ion-list>
<ion-item ng-repeat="people in peopleList">
{{people.firstname}} {{people.lastname}}
<ion-option-button class="button-assertive icon ion-trash-a" ng-click='delete(people.lastname)'></ion-option-button>
</ion-item>
</ion-list>
</ion-content>
</ion-pane>
</body>
</html>
26
Step by Step – app.js
// Database instance.
var db = null;
// Include dependency: ngCordova
var starter = angular.module('starter', ['ionic', '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) {
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB({name: "my.db"});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS pessoas (id INTEGER PRIMARY KEY, firstname text, lastname text)");
});
})
starter.controller('DBController', function($scope, $cordovaSQLite) {
$scope.resultado = "";
$scope.peopleList = [];
$scope.insert = function(firstname, lastname) {
$scope.peopleList = [];
var query = "insert into pessoas (firstname, lastname) values (?,?)";
$cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) {
//$scope.resultado.push({mensagem: "Insert Ok"});
$scope.resultado = "Insert OK.";
}, function(error){
$scope.resultado = "Insert FAIL!";
});
}
27
Step by Step – app.js - cont
$scope.select = function(lastname){
$scope.peopleList = [];
var query = "select firstname, lastname from pessoas where lastname = ?";
$cordovaSQLite.execute(db,query,[lastname]).then(function(result) {
if(result.rows.length > 0){
$scope.resultado = result.rows.item(0).firstname + " found with this last name.";
} else {
$scope.resultado = "Last Name Not Found!";
}
}, function(error){
console.log(error);
});
}
$scope.selectAll = function(){
$scope.peopleList = [];
var query = "select firstname, lastname from pessoas";
$cordovaSQLite.execute(db,query,[]).then(function(result) {
if(result.rows.length > 0){
for(var i = 0; i < result.rows.length; i++) {
$scope.peopleList.push({firstname: result.rows.item(i).firstname, lastname: result.rows.item(i).lastname});
}
$scope.resultado = result.rows.length + " rows found.";
} else {
$scope.resultado = "0 rows found!";
$scope.peopleList = [];
}
}, function(error){
console.log(error);
});
}
$scope.delete = function(lastname) {
$scope.peopleList = [];
var query = "delete from pessoas where lastname = ?";
$cordovaSQLite.execute(db,query,[lastname]).then(function(result) {
$scope.resultado = "Delete Ok.";
}, function(error){
$scope.resultado = "Delete FAIL!";
});
}
28
Step by Step – app.js - cont
$scope.update = function(firstname, lastname) {
$scope.peopleList = [];
var query = "update pessoas set firstname = ? where lastname = ?";
$cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) {
$scope.resultado = "Update OK.";
}, function(error){
$scope.resultado = "Update FAIL!";
});
}
// you can add a button to cleat he table!
$scope.deleteAll = function() {
$scope.peopleList = [];
var query = "delete from pessoas";
$cordovaSQLite.execute(db,query,[]).then(function(result) {
$scope.resultado = "Delete Ok.";
}, function(error){
$scope.resultado = "Delete FAIL!";
});
}
});
29
Step by Step
● Let's run with the command (you need to have an emulator or your physical phone
connected, in my case, I have Genymotion running):
ionic run android
30
To do!
● We have some things that we can make better:
● Need to validate data that user enter, like empty names.
● Clear the form after the submit
You can get the source code from this slides here →
https://github.com/julianommartins/ionicDataBase.git
31
Links
● Ionic JavaScript functionalities
http://ionicframework.com/docs/api/
● Ionic CSS
http://ionicframework.com/docs/components/
● Ionic Creator
http://creator.ionic.io/app/login
● Extensions for Cordova API
http://ngcordova.com/
32
All text and image content in this document is licensed under the Creative Commons Attribution-Share Alike 3.0 License
(unless otherwise specified). Adobe, Google, Apple, Apache, and other are registered trademarks. Their respective logos and
icons are subject to international copyright laws.
Thank you …
… for your dedication and patience!

Mais conteúdo relacionado

Mais procurados

Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentBrad Williams
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksGerald Krishnan
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBen Limmer
 
Introduction to JQuery, ASP.NET MVC and Silverlight
Introduction to JQuery, ASP.NET MVC and SilverlightIntroduction to JQuery, ASP.NET MVC and Silverlight
Introduction to JQuery, ASP.NET MVC and SilverlightPeter Gfader
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010Nicholas Zakas
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)Steve Souders
 
Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWebDave Bouwman
 
JavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemJavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemAlexander Casall
 
Vue js and Vue Material
Vue js and Vue MaterialVue js and Vue Material
Vue js and Vue MaterialEueung Mulyana
 
What The Flask? and how to use it with some Google APIs
What The Flask? and how to use it with some Google APIsWhat The Flask? and how to use it with some Google APIs
What The Flask? and how to use it with some Google APIsBruno Rocha
 
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CIPython Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CIBruno Rocha
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupalsparkfabrik
 
Build website in_django
Build website in_django Build website in_django
Build website in_django swee meng ng
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Steve Souders
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)Alexander Casall
 
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Google I/O 2012 - Protecting your user experience while integrating 3rd party...Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Google I/O 2012 - Protecting your user experience while integrating 3rd party...Patrick Meenan
 

Mais procurados (20)

Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
 
JavaFX Advanced
JavaFX AdvancedJavaFX Advanced
JavaFX Advanced
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profit
 
Introduction to JQuery, ASP.NET MVC and Silverlight
Introduction to JQuery, ASP.NET MVC and SilverlightIntroduction to JQuery, ASP.NET MVC and Silverlight
Introduction to JQuery, ASP.NET MVC and Silverlight
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWeb
 
JavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemJavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and Ecosystem
 
Vue js and Vue Material
Vue js and Vue MaterialVue js and Vue Material
Vue js and Vue Material
 
What The Flask? and how to use it with some Google APIs
What The Flask? and how to use it with some Google APIsWhat The Flask? and how to use it with some Google APIs
What The Flask? and how to use it with some Google APIs
 
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CIPython Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
 
Build website in_django
Build website in_django Build website in_django
Build website in_django
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)
 
WPDay Bologna 2013
WPDay Bologna 2013WPDay Bologna 2013
WPDay Bologna 2013
 
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Google I/O 2012 - Protecting your user experience while integrating 3rd party...Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
 
Jsf 2.0 in depth
Jsf 2.0 in depthJsf 2.0 in depth
Jsf 2.0 in depth
 

Destaque

Desmistificando Tecnologias
Desmistificando TecnologiasDesmistificando Tecnologias
Desmistificando TecnologiasJuliano Martins
 
Introdução a Big Data e Apache Solr
Introdução a Big Data e Apache SolrIntrodução a Big Data e Apache Solr
Introdução a Big Data e Apache SolrJuliano Martins
 
Criando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphere
Criando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphereCriando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphere
Criando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphereJuliano Martins
 
Software livre em minha carreira
Software livre em minha carreiraSoftware livre em minha carreira
Software livre em minha carreiraJuliano Martins
 
IBM - The 7 Keys to Success - MoMoDar
IBM - The 7 Keys to Success - MoMoDarIBM - The 7 Keys to Success - MoMoDar
IBM - The 7 Keys to Success - MoMoDarHamisi Kibonde
 
Building Mobile Apps with Cordova , AngularJS and Ionic
Building Mobile Apps with Cordova , AngularJS and IonicBuilding Mobile Apps with Cordova , AngularJS and Ionic
Building Mobile Apps with Cordova , AngularJS and IonicKadhem Soltani
 
A experiência do usuário na Web
A experiência do usuário na WebA experiência do usuário na Web
A experiência do usuário na WebWellington Oliveira
 
php4android: desenvolva aplicações android em PHP
php4android: desenvolva aplicações android em PHPphp4android: desenvolva aplicações android em PHP
php4android: desenvolva aplicações android em PHPRamon Ribeiro Rabello
 
Offline apps Using Ionic Framework and PouchDB
Offline apps  Using Ionic Framework and PouchDBOffline apps  Using Ionic Framework and PouchDB
Offline apps Using Ionic Framework and PouchDBAlvaro Viebrantz
 
Effective Communication Of Data Inspired by Stephen Few
Effective Communication Of Data Inspired by Stephen FewEffective Communication Of Data Inspired by Stephen Few
Effective Communication Of Data Inspired by Stephen FewCory Grenier
 
Rethinking Mobile with Ionic
Rethinking Mobile with IonicRethinking Mobile with Ionic
Rethinking Mobile with IonicMike Hartington
 
Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)ColdFusionConference
 
Ionic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf SteroidenIonic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf SteroidenHendrik Lösch
 
Cordova, Angularjs & Ionic @ Codeaholics
Cordova, Angularjs & Ionic @ CodeaholicsCordova, Angularjs & Ionic @ Codeaholics
Cordova, Angularjs & Ionic @ CodeaholicsEddie Lau
 
Ionic Framework - get up and running to build hybrid mobile apps
Ionic Framework - get up and running to build hybrid mobile appsIonic Framework - get up and running to build hybrid mobile apps
Ionic Framework - get up and running to build hybrid mobile appsAndreas Sahle
 
Art and Science of Dashboard Design
Art and Science of Dashboard DesignArt and Science of Dashboard Design
Art and Science of Dashboard DesignSavvyData
 
Hybrid app in ionic framework overview
Hybrid app in ionic framework overviewHybrid app in ionic framework overview
Hybrid app in ionic framework overviewSanket Devlekar
 
Hybrid Apps with Ionic Framework
Hybrid Apps with Ionic FrameworkHybrid Apps with Ionic Framework
Hybrid Apps with Ionic FrameworkBramus Van Damme
 
Building mobile app with Ionic Framework
Building mobile app with Ionic FrameworkBuilding mobile app with Ionic Framework
Building mobile app with Ionic FrameworkHuy Trần
 

Destaque (20)

Desmistificando Tecnologias
Desmistificando TecnologiasDesmistificando Tecnologias
Desmistificando Tecnologias
 
Introdução a Big Data e Apache Solr
Introdução a Big Data e Apache SolrIntrodução a Big Data e Apache Solr
Introdução a Big Data e Apache Solr
 
Criando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphere
Criando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphereCriando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphere
Criando um Web Service Restful com Jersey, Eclipse, JBoss, Tomcat, WebSphere
 
Software livre em minha carreira
Software livre em minha carreiraSoftware livre em minha carreira
Software livre em minha carreira
 
IBM - The 7 Keys to Success - MoMoDar
IBM - The 7 Keys to Success - MoMoDarIBM - The 7 Keys to Success - MoMoDar
IBM - The 7 Keys to Success - MoMoDar
 
Building Mobile Apps with Cordova , AngularJS and Ionic
Building Mobile Apps with Cordova , AngularJS and IonicBuilding Mobile Apps with Cordova , AngularJS and Ionic
Building Mobile Apps with Cordova , AngularJS and Ionic
 
A experiência do usuário na Web
A experiência do usuário na WebA experiência do usuário na Web
A experiência do usuário na Web
 
php4android: desenvolva aplicações android em PHP
php4android: desenvolva aplicações android em PHPphp4android: desenvolva aplicações android em PHP
php4android: desenvolva aplicações android em PHP
 
Offline apps Using Ionic Framework and PouchDB
Offline apps  Using Ionic Framework and PouchDBOffline apps  Using Ionic Framework and PouchDB
Offline apps Using Ionic Framework and PouchDB
 
Effective Communication Of Data Inspired by Stephen Few
Effective Communication Of Data Inspired by Stephen FewEffective Communication Of Data Inspired by Stephen Few
Effective Communication Of Data Inspired by Stephen Few
 
Rethinking Mobile with Ionic
Rethinking Mobile with IonicRethinking Mobile with Ionic
Rethinking Mobile with Ionic
 
Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)
 
Ionic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf SteroidenIonic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf Steroiden
 
Cordova, Angularjs & Ionic @ Codeaholics
Cordova, Angularjs & Ionic @ CodeaholicsCordova, Angularjs & Ionic @ Codeaholics
Cordova, Angularjs & Ionic @ Codeaholics
 
Ionic Framework - get up and running to build hybrid mobile apps
Ionic Framework - get up and running to build hybrid mobile appsIonic Framework - get up and running to build hybrid mobile apps
Ionic Framework - get up and running to build hybrid mobile apps
 
Workshop Ionic Framework - CC FE & UX
Workshop Ionic Framework - CC FE & UXWorkshop Ionic Framework - CC FE & UX
Workshop Ionic Framework - CC FE & UX
 
Art and Science of Dashboard Design
Art and Science of Dashboard DesignArt and Science of Dashboard Design
Art and Science of Dashboard Design
 
Hybrid app in ionic framework overview
Hybrid app in ionic framework overviewHybrid app in ionic framework overview
Hybrid app in ionic framework overview
 
Hybrid Apps with Ionic Framework
Hybrid Apps with Ionic FrameworkHybrid Apps with Ionic Framework
Hybrid Apps with Ionic Framework
 
Building mobile app with Ionic Framework
Building mobile app with Ionic FrameworkBuilding mobile app with Ionic Framework
Building mobile app with Ionic Framework
 

Semelhante a Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, acessando SQLite

SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFesttomdale
 
Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020Matt Raible
 
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Innomatic Platform
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Filippo Matteo Riggio
 
Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Loïc Knuchel
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJSBrajesh Yadav
 
Mobile Apps with PhoneGap and jQuery Mobile
Mobile Apps with PhoneGap and jQuery MobileMobile Apps with PhoneGap and jQuery Mobile
Mobile Apps with PhoneGap and jQuery MobileTerry Ryan
 
Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.tothepointIT
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e bigAndy Peterson
 
HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushEvan Schultz
 
AppForum 2014 Boost Hybrid App Performance
AppForum 2014 Boost Hybrid App PerformanceAppForum 2014 Boost Hybrid App Performance
AppForum 2014 Boost Hybrid App Performancerobgalvinjr
 
Meteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoMeteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoArabNet ME
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In ActionHazem Saleh
 
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...Positive Hack Days
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 

Semelhante a Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, acessando SQLite (20)

Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFest
 
Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020Front End Development for Back End Java Developers - Jfokus 2020
Front End Development for Back End Java Developers - Jfokus 2020
 
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
 
React django
React djangoReact django
React django
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2
 
Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
 
Mobile Apps with PhoneGap and jQuery Mobile
Mobile Apps with PhoneGap and jQuery MobileMobile Apps with PhoneGap and jQuery Mobile
Mobile Apps with PhoneGap and jQuery Mobile
 
Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePush
 
AppForum 2014 Boost Hybrid App Performance
AppForum 2014 Boost Hybrid App PerformanceAppForum 2014 Boost Hybrid App Performance
AppForum 2014 Boost Hybrid App Performance
 
Meteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoMeteor.js Workshop by Dopravo
Meteor.js Workshop by Dopravo
 
Mobile optimization
Mobile optimizationMobile optimization
Mobile optimization
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
 
Os Haase
Os HaaseOs Haase
Os Haase
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
 
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 

Último

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, acessando SQLite

  • 1. 1 Creating a CRUD with Ionic – Part 1 Juliano Marcos Martins – juliano.jmm@gmail.com http://jmmwrite.wordpress.com
  • 2. 2 SQLite Is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. https://www.sqlite.org/
  • 3. 3 Local Storage Can be used to store data, but don't Assume that it will Always Work In Your Hybrid App. // example localStorage.setItem('nome', 'Juliano'); var name = localStorage.getItem('nome'); console.log(name); IOs and Android can clean it in some situations.
  • 4. 4 Intro We will create an application to manage people from a table. Its recommended that you already have basic concepts about Ionic and Mobile Development before go ahead. For more intro material, check my blog: http://jmmwrite.wordpress.com/ You can get the source code from this slides here → https://github.com/julianommartins/ionicDataBase.git
  • 5. 5 Step by Step ● Create the project ionic start ionicDataBase blank
  • 6. 6 Step by Step ● Enter in the project folder and Add platform: ionic platform add android
  • 7. 7 Step by Step ● Add SQLite module (documentation: http://ngcordova.com/docs/plugins/sqlite/ ): cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git
  • 8. 8 Step by Step ● Go to http://ngcordova.com/docs/install/ and get the JS lib (download the zip file) ● Extract it and get ng-cordova.min.js , put this file in the JS folder of your application * You can also use bower to get ng-cordova
  • 9. 9 Step by Step ● Open your index.html file and import ng-cordova there by adding the folowing line BEFORE cordova import: <script src="js/ng-cordova.min.js"></script>:
  • 10. 10 Step by Step ● Open your app.js file and inject ngCordova module: This will make module work!
  • 11. 11 Step by Step – index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>DB Example</title> <link href="lib/ionic/css/ionic.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet"> <!-- ionic/angularjs js --> <script src="lib/ionic/js/ionic.bundle.js"></script> <!-- cordova script (this will be a 404 during development) --> <script src="js/ng-cordova.min.js"></script> <script src="cordova.js"></script> <!-- your app's js --> <script src="js/app.js"></script> </head> <body ng-app="starter"> <ion-pane> <ion-header-bar class="bar-stable"> <h1 class="title">Pessoas</h1> </ion-header-bar> <ion-content ng-controller="DBController"> <button class="button" ng-click="insert('Juliano','Martins')">Insert</button> <button class="button" ng-click="select('Martins')">Select</button> Resultado: {{mensagemFinal}} Resultado: {{resultado}} </ion-content> </ion-pane> </body> </html>
  • 12. 12 Step by Step – app.js // Database instance. var db = null; // Include dependency: ngCordova var starter = angular.module('starter', ['ionic', '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) { StatusBar.styleDefault(); } db = $cordovaSQLite.openDB({name: "my.db"}); $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS pessoas (id INTEGER PRIMARY KEY, firstname text, lastname text)"); }); }) starter.controller('DBController', function($scope, $cordovaSQLite) { $scope.resultado = []; $scope.mensagemFinal = "Iniciou Sistema"; $scope.insert = function(firstname, lastname) { var query = "insert into pessoas (firstname, lastname) values (?,?)"; $cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) { $scope.mensagemFinal = "FOI"; $scope.resultado.push({mensagem: "Insert Ok"}); console.log("Insert ID -> " + result.insertId); }, function(error){ $scope.resultado.push({mensagem: "insert Fail"}); $scope.mensagemFinal = "Fail"; console.log(error); }); }
  • 13. 13 Step by Step – app.js - continuation $scope.select = function(lastname){ var query = "select firstname, lastname from pessoas where lastname = ?"; $cordovaSQLite.execute(db,query,[lastname]).then(function(result) { if(result.rows.length > 0){ $scope.mensagemFinal = "ACHEI"; $scope.resultado = result.rows.item(0).firstname; console.log("Achei " + result.rows.item(0).firstname + " " + result.rows.item(0).lastname); } else { $scope.mensagemFinal = "NAO ACHEI"; $scope.resultado = []; console.log("Nao achei"); } }, function(error){ console.log(error); }); } });
  • 14. 14 Step by Step ● Let's run with the command (you need to have an emulator or your physical phone connected, in my case, I have Genymotion running): ionic run android
  • 15. 15 TIP ● To see the Android log, go to the folder platform-tools from your sdk and run: ./adb logcat ● This is for Linux.
  • 16. 16 Creating a CRUD with Ionic – Part 2 Juliano Marcos Martins – juliano.jmm@gmail.com http://jmmwrite.wordpress.com
  • 17. 17 Part 2 ● We have created a code that insert and search for names, but, its hardcoded! ● Now we will create a FORM, to allow user type First and Last names and perform the Insert and Search Operations with this data. ● We are not wondering about form validation for now, but, we will create a better UI at least! You can get the source code from this slides here → https://github.com/julianommartins/ionicDataBase.git
  • 18. 18 Step by Step – index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>DB Example</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> </head> <body ng-app="starter"> <ion-pane ng-controller="DBController"> <ion-header-bar class="bar-positive"> <h1 class="title">Pessoas</h1> </ion-header-bar> <ion-content> <div class="list"> <label class="item item-input item-floating-label"> <span class="input-label">First Name</span> <input type="text" placeholder="First Name" data-ng-model="fsName"> </label> <label class="item item-input item-floating-label"> <span class="input-label">Last Name</span> <input type="text" placeholder="Last Name" data-ng-model="lstName"> </label> <button class="button button-balanced" ng-click="select(lstName)">Select</button> <button class="button button-positive" ng-click="insert(fsName,lstName)">Insert</button> <button class="button button-energized" ng-click="delete(lstName)">Delete</button> <button class="button button-assertive" ng-click="update(fsName,lstName)">Update</button> <label class="item item-input"> <input type="text" readonly value="{{resultado}}"> </label> </div> </ion-content> <ion-footer-bar class="bar-positive"> <h1 class="title">Pessoas</h1> </ion-footer-bar> </ion-pane> </body> </html>
  • 19. 19 Step by Step – app.js // Database instance. var db = null; // Include dependency: ngCordova var starter = angular.module('starter', ['ionic', '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) { StatusBar.styleDefault(); } db = $cordovaSQLite.openDB({name: "my.db"}); $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS pessoas (id INTEGER PRIMARY KEY, firstname text, lastname text)"); }); }) starter.controller('DBController', function($scope, $cordovaSQLite) { $scope.resultado = ""; $scope.insert = function(firstname, lastname) { var query = "insert into pessoas (firstname, lastname) values (?,?)"; $cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) { //$scope.resultado.push({mensagem: "Insert Ok"}); $scope.resultado = "Insert Ok"; }, function(error){ $scope.resultado = "Insert FAIL"; }); }
  • 20. 20 Step by Step – app.js (continuation) $scope.select = function(lastname){ var query = "select firstname, lastname from pessoas where lastname = ?"; $cordovaSQLite.execute(db,query,[lastname]).then(function(result) { if(result.rows.length > 0){ $scope.resultado = result.rows.item(0).firstname + " found with this last name."; } else { $scope.resultado = "Not found"; } }, function(error){ console.log(error); }); } });
  • 21. 21 Step by Step ● Let's run with the command (you need to have an emulator or your physical phone connected, in my case, I have Genymotion running): ionic run android
  • 22. 22 Part 3 ● Now, lets implement the update and delete operations. You can get the source code from this slides here → https://github.com/julianommartins/ionicDataBase.git
  • 23. 23 Step by Step – app.js $scope.delete = function(lastname) { var query = "delete from pessoas where lastname = ?"; $cordovaSQLite.execute(db,query,[lastname]).then(function(result) { $scope.resultado = "Delete Ok."; }, function(error){ $scope.resultado = "Delete FAIL!"; }); } $scope.update = function(firstname, lastname) { var query = "update pessoas set firstname = ? where lastname = ?"; $cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) { $scope.resultado = "Update OK."; }, function(error){ $scope.resultado = "Update FAIL!"; }); } Just add this functions to app.js
  • 24. 24 Part 4 ● We have a Functional Crud, but now, we want a function to list all the people from DB! ● Also, we will remove the delete button and put it in the list, to let user swipe the user in order to remove. You can get the source code from this slides here → https://github.com/julianommartins/ionicDataBase.git
  • 25. 25 Step by Step – index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>DB Example</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> </head> <body ng-app="starter"> <ion-pane ng-controller="DBController"> <ion-header-bar class="bar-positive"> <h1 class="title">People List</h1> </ion-header-bar> <ion-content> <label class="item item-input item-floating-label"> <span class="input-label">First Name</span> <input type="text" placeholder="First Name" data-ng-model="fsName"> </label> <label class="item item-input item-floating-label"> <span class="input-label">Last Name</span> <input type="text" placeholder="Last Name" data-ng-model="lstName"> </label> <button class="button button-balanced" ng-click="select(lstName)">Select</button> <button class="button button-positive" ng-click="insert(fsName,lstName)">Insert</button> <button class="button button-energized" ng-click="update(fsName,lstName)">Update</button> <button class="button button-royal" ng-click="selectAll()">List</button> <label class="item item-input"> <input type="text" readonly value="{{resultado}}"> </label> <ion-list> <ion-item ng-repeat="people in peopleList"> {{people.firstname}} {{people.lastname}} <ion-option-button class="button-assertive icon ion-trash-a" ng-click='delete(people.lastname)'></ion-option-button> </ion-item> </ion-list> </ion-content> </ion-pane> </body> </html>
  • 26. 26 Step by Step – app.js // Database instance. var db = null; // Include dependency: ngCordova var starter = angular.module('starter', ['ionic', '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) { StatusBar.styleDefault(); } db = $cordovaSQLite.openDB({name: "my.db"}); $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS pessoas (id INTEGER PRIMARY KEY, firstname text, lastname text)"); }); }) starter.controller('DBController', function($scope, $cordovaSQLite) { $scope.resultado = ""; $scope.peopleList = []; $scope.insert = function(firstname, lastname) { $scope.peopleList = []; var query = "insert into pessoas (firstname, lastname) values (?,?)"; $cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) { //$scope.resultado.push({mensagem: "Insert Ok"}); $scope.resultado = "Insert OK."; }, function(error){ $scope.resultado = "Insert FAIL!"; }); }
  • 27. 27 Step by Step – app.js - cont $scope.select = function(lastname){ $scope.peopleList = []; var query = "select firstname, lastname from pessoas where lastname = ?"; $cordovaSQLite.execute(db,query,[lastname]).then(function(result) { if(result.rows.length > 0){ $scope.resultado = result.rows.item(0).firstname + " found with this last name."; } else { $scope.resultado = "Last Name Not Found!"; } }, function(error){ console.log(error); }); } $scope.selectAll = function(){ $scope.peopleList = []; var query = "select firstname, lastname from pessoas"; $cordovaSQLite.execute(db,query,[]).then(function(result) { if(result.rows.length > 0){ for(var i = 0; i < result.rows.length; i++) { $scope.peopleList.push({firstname: result.rows.item(i).firstname, lastname: result.rows.item(i).lastname}); } $scope.resultado = result.rows.length + " rows found."; } else { $scope.resultado = "0 rows found!"; $scope.peopleList = []; } }, function(error){ console.log(error); }); } $scope.delete = function(lastname) { $scope.peopleList = []; var query = "delete from pessoas where lastname = ?"; $cordovaSQLite.execute(db,query,[lastname]).then(function(result) { $scope.resultado = "Delete Ok."; }, function(error){ $scope.resultado = "Delete FAIL!"; }); }
  • 28. 28 Step by Step – app.js - cont $scope.update = function(firstname, lastname) { $scope.peopleList = []; var query = "update pessoas set firstname = ? where lastname = ?"; $cordovaSQLite.execute(db,query,[firstname,lastname]).then(function(result) { $scope.resultado = "Update OK."; }, function(error){ $scope.resultado = "Update FAIL!"; }); } // you can add a button to cleat he table! $scope.deleteAll = function() { $scope.peopleList = []; var query = "delete from pessoas"; $cordovaSQLite.execute(db,query,[]).then(function(result) { $scope.resultado = "Delete Ok."; }, function(error){ $scope.resultado = "Delete FAIL!"; }); } });
  • 29. 29 Step by Step ● Let's run with the command (you need to have an emulator or your physical phone connected, in my case, I have Genymotion running): ionic run android
  • 30. 30 To do! ● We have some things that we can make better: ● Need to validate data that user enter, like empty names. ● Clear the form after the submit You can get the source code from this slides here → https://github.com/julianommartins/ionicDataBase.git
  • 31. 31 Links ● Ionic JavaScript functionalities http://ionicframework.com/docs/api/ ● Ionic CSS http://ionicframework.com/docs/components/ ● Ionic Creator http://creator.ionic.io/app/login ● Extensions for Cordova API http://ngcordova.com/
  • 32. 32 All text and image content in this document is licensed under the Creative Commons Attribution-Share Alike 3.0 License (unless otherwise specified). Adobe, Google, Apple, Apache, and other are registered trademarks. Their respective logos and icons are subject to international copyright laws. Thank you … … for your dedication and patience!