SlideShare a Scribd company logo
1 of 20
1
Step by Step
Juliano Marcos Martins – juliano.jmm@gmail.com
http://jmmwrite.wordpress.com
2
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.
Lets create a brand new application to lists Blogs
entries from my blog at Wordpress.
3
Step by Step - 1
● Create a simple application to list the post from my blog:
● My blog: https://jmmwrite.wordpress.com/
● Wordpress REST Documentation: https://developer.wordpress.com/docs/api/
4
Step by Step – 1.1
● Getting posts URL (try to hit this URL at your browser):
https://public-api.wordpress.com/rest/v1.1/sites/jmmwrite.wordpress.com/posts/?number=2
● Number its the number of posts to retrieve. Default is 20
● See that each post have many attributes, what we care now is TITLE and excerpt
5
Step by Step – 2 – Create a Blank project
●ionic start lePosts blank
It create some files and folders.
What matter to us now, is the WWW folder.
6
Step by Step – 3 – Edit index.html
<!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">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<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">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content>
</ion-content>
</ion-pane>
</body>
</html>
This is the original Index
file created by Ionic
7
Step by Step – 3.1 – Edit index.html
<!DOCTYPE html>
<html lang="en" ng-app="lePosts">
<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">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-controller="lePostsCtrl">
<ion-pane>
<ion-header-bar class="bar-dark">
<h1 class="title">Posts</h1>
</ion-header-bar>
<ion-content>
<ion-refresher pulling-text="Reload blogs" on-refresh="reload()"></ion-refresher>
<ion-list>
<ion-item ng-repeat="b in blogs" ng-click="show($index)">
<h2 ng-bind-html="b.title"></h2>
<p>{{b.name}}</p>
<p>{{b.URL}}</p>
<ion-option-button class="button-energized" ng-click="share($index)">
Share
</ion-option-button>
</ion-item>
</ion-list>
<ion-infinite-scroll on-infinite="loadMore()" ng-if="deviceReady"></ion-infinite-scroll>
</ion-content>
</ion-pane>
</body>
</html>
This is the final version,
see that we changed
many things. Be careful
with cut and paste. You
can delete all the
content of your index file
and paste this there.
8
Step by Step – 4 – Edit the app.js file
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$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();
}
});
})
Inside js, you can find
this file. This is the
original file created by
Ionic.
9
Step by Step – 4.1 – Edit the app.js file
var lePosts = angular.module("lePosts", ["ionic"]);
lePosts.service("lePostsSvc", ["$http", "$rootScope", lePostsSvc]);
lePosts.controller("lePostsCtrl",
["$scope", "$sce",
"$ionicLoading", "$ionicListDelegate", "$ionicPlatform",
"lePostsSvc", lePostsCtrl]);
function lePostsCtrl($scope, $sce, $ionicLoading, $ionicListDelegate, $ionicPlatform, lePostsSvc) {
$ionicLoading.show({template: "Loading blogs..."});
$scope.deviceReady = false;
$ionicPlatform.ready(function() {
$scope.$apply(function() {
$scope.deviceReady = true;
});
});
$scope.blogs = [];
$scope.params = {};
$scope.$on("lePosts.blogs", function(_, result) {
result.posts.forEach(function(b) {
$scope.blogs.push({
name: b.author.name,
avatar_URL: b.author.avatar_URL,
title: $sce.trustAsHtml(b.title),
URL: b.URL,
excerpt: $sce.trustAsHtml(b.excerpt),
featured_image: b.featured_image
});
});
Here is the edited file. Its
big, so, it continue in the
next slide. Use this.
10
Step by Step – 4.1 – Edit the app.js file - cont
$scope.$broadcast("scroll.infiniteScrollComplete");
$scope.$broadcast("scroll.refreshComplete");
$ionicLoading.hide();
});
$scope.loadMore = function() {
lePostsSvc.loadBlogs($scope.params);
}
$scope.reload = function() {
$scope.blogs = [];
$scope.params = {};
lePostsSvc.loadBlogs();
}
$scope.show = function($index) {
cordova.InAppBrowser.open($scope.blogs[$index].URL, "_blank", "location=no");
}
$scope.share = function($index) {
$ionicListDelegate.closeOptionButtons();
window.socialmessage.send({
url: $scope.blogs[$index].URL
});
}
}
function lePostsSvc($http, $rootScope) {
this.loadBlogs = function(params) {
$http.get("https://public-api.wordpress.com/rest/v1.1/sites/jmmwrite.wordpress.com/posts/", {
params: params})
.success(function(result) {
$rootScope.$broadcast("lePosts.blogs", result);
});
}
}
Here is the edited file
continuation. Take care
to copy and paste and
do not loose any piece
of code.
11
Step by Step – A pause to explanations...
So far we:
● Created a new project
● Edited the index page that will hold the list of blogs. There, we set up the Controller that
will make the magic. See that we have a FOR loop to list the posts. We also created a
functionality to reload blogs when user pull text and load more when user scroll down.
● In the controller, we created a service that connect to the wordpress feed and put the
results in the array called blogs.
● You can separate controller and services in more files to organize your code.
12
Step by Step – 5 – Testing at your browser
● Now, in the command line, got to your app folder root, in my case:
[~/workspaceIonic/lePosts]$ pwd
/home/julianom/workspaceIonic/lePosts
● Run the command:
ionic serve
Test now.
13
Step by Step – 5.1 – Testing at your browser
●With the following command, you can test simulating a phone appearance:
ionic serve --lab
Test now.
14
Step by Step – TIP
● At your browser, ALWAYS run taking a look in the Console, it can help you to find errors,
for example:
15
Step by Step – TIP 2
● When you change html, js, css, Ionic Serve will reload it, and you just need to reload the
page at your browser. In some cases this will not work properly, so, its better close Ionic
Serve (type q in the console), and start again.
16
Step by Step – 6 – Testing in the Phone
● First of all, you need to add Platform, in my case, Android. Run the command (inside
your app folder):
ionic platform add android
17
Step by Step – 6 – Testing in the Phone
● Then, in order to run, you need to have your environment OK. Remember to perform
the installations from the previous slides. In my case, I have started genymotion, then, I
run the command:
ionic run android
18
Step by Step – Exercises
1- We have a Bug in the project:
● When pulling up, app load more blogs entries, but it repeat the entries! How to solve?
2- When user click URL, you should open it ;)
19
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/
● Example with Google Maps
http://codepen.io/ionic/pen/uzngt
● Interesting Article about IOs native dev migration to Ionic
https://www.airpair.com/javascript/posts/switching-from-ios-to-ionic
● How to deploy to App Store
https://medium.com/@_qzapaia/deploy-an-ionic-app-to-the-ios-app-store-702c79a2dd97
● SQLite example
● https://blog.nraboy.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/
20
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!

More Related Content

What's hot

Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2
Byrne Reese
 
Building Progressive Web Apps for Android and iOS
Building Progressive Web Apps for Android and iOSBuilding Progressive Web Apps for Android and iOS
Building Progressive Web Apps for Android and iOS
FITC
 

What's hot (20)

lecture5
lecture5lecture5
lecture5
 
What Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsWhat Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 Apps
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
 
State of jQuery '09
State of jQuery '09State of jQuery '09
State of jQuery '09
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery Plugins
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Building mobile applications with DrupalGap
Building mobile applications with DrupalGapBuilding mobile applications with DrupalGap
Building mobile applications with DrupalGap
 
JUG Utrecht 2013 - Have you tried turning it off and on again? Problemen oplo...
JUG Utrecht 2013 - Have you tried turning it off and on again? Problemen oplo...JUG Utrecht 2013 - Have you tried turning it off and on again? Problemen oplo...
JUG Utrecht 2013 - Have you tried turning it off and on again? Problemen oplo...
 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin Development
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
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
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
 
Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2
 
Troubleshooting Joomla! problems - Joomladay Germany 2014
Troubleshooting Joomla! problems - Joomladay Germany 2014Troubleshooting Joomla! problems - Joomladay Germany 2014
Troubleshooting Joomla! problems - Joomladay Germany 2014
 
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
 
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
 
Building Progressive Web Apps for Android and iOS
Building Progressive Web Apps for Android and iOSBuilding Progressive Web Apps for Android and iOS
Building Progressive Web Apps for Android and iOS
 

Similar to Passo a Passo para criar uma aplicação Móvel Híbrida

Plug in development
Plug in developmentPlug in development
Plug in development
Lucky Ali
 

Similar to Passo a Passo para criar uma aplicação Móvel Híbrida (20)

End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 
React django
React djangoReact django
React django
 
Django simplified : by weever mbakaya
Django simplified : by weever mbakayaDjango simplified : by weever mbakaya
Django simplified : by weever mbakaya
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
 
Angularjs Tutorial for Beginners
Angularjs Tutorial for BeginnersAngularjs Tutorial for Beginners
Angularjs Tutorial for Beginners
 
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...
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
Spring Lab
Spring LabSpring Lab
Spring Lab
 
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
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budget
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
Обход проверки безопасности в магазинах мобильных приложений при помощи платф...
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Cordova iOS Native Plugin Development
Cordova iOS Native Plugin DevelopmentCordova iOS Native Plugin Development
Cordova iOS Native Plugin Development
 
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)
 
Frontend Workflow
Frontend WorkflowFrontend Workflow
Frontend Workflow
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
+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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Passo a Passo para criar uma aplicação Móvel Híbrida

  • 1. 1 Step by Step Juliano Marcos Martins – juliano.jmm@gmail.com http://jmmwrite.wordpress.com
  • 2. 2 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. Lets create a brand new application to lists Blogs entries from my blog at Wordpress.
  • 3. 3 Step by Step - 1 ● Create a simple application to list the post from my blog: ● My blog: https://jmmwrite.wordpress.com/ ● Wordpress REST Documentation: https://developer.wordpress.com/docs/api/
  • 4. 4 Step by Step – 1.1 ● Getting posts URL (try to hit this URL at your browser): https://public-api.wordpress.com/rest/v1.1/sites/jmmwrite.wordpress.com/posts/?number=2 ● Number its the number of posts to retrieve. Default is 20 ● See that each post have many attributes, what we care now is TITLE and excerpt
  • 5. 5 Step by Step – 2 – Create a Blank project ●ionic start lePosts blank It create some files and folders. What matter to us now, is the WWW folder.
  • 6. 6 Step by Step – 3 – Edit index.html <!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"> <!-- ionic/angularjs js --> <script src="lib/ionic/js/ionic.bundle.js"></script> <!-- cordova script (this will be a 404 during development) --> <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">Ionic Blank Starter</h1> </ion-header-bar> <ion-content> </ion-content> </ion-pane> </body> </html> This is the original Index file created by Ionic
  • 7. 7 Step by Step – 3.1 – Edit index.html <!DOCTYPE html> <html lang="en" ng-app="lePosts"> <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"> <!-- ionic/angularjs js --> <script src="lib/ionic/js/ionic.bundle.js"></script> <!-- cordova script (this will be a 404 during development) --> <script src="cordova.js"></script> <!-- your app's js --> <script src="js/app.js"></script> </head> <body ng-controller="lePostsCtrl"> <ion-pane> <ion-header-bar class="bar-dark"> <h1 class="title">Posts</h1> </ion-header-bar> <ion-content> <ion-refresher pulling-text="Reload blogs" on-refresh="reload()"></ion-refresher> <ion-list> <ion-item ng-repeat="b in blogs" ng-click="show($index)"> <h2 ng-bind-html="b.title"></h2> <p>{{b.name}}</p> <p>{{b.URL}}</p> <ion-option-button class="button-energized" ng-click="share($index)"> Share </ion-option-button> </ion-item> </ion-list> <ion-infinite-scroll on-infinite="loadMore()" ng-if="deviceReady"></ion-infinite-scroll> </ion-content> </ion-pane> </body> </html> This is the final version, see that we changed many things. Be careful with cut and paste. You can delete all the content of your index file and paste this there.
  • 8. 8 Step by Step – 4 – Edit the app.js file // Ionic Starter App // angular.module is a global place for creating, registering and retrieving Angular modules // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) // the 2nd parameter is an array of 'requires' angular.module('starter', ['ionic']) .run(function($ionicPlatform) { $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(); } }); }) Inside js, you can find this file. This is the original file created by Ionic.
  • 9. 9 Step by Step – 4.1 – Edit the app.js file var lePosts = angular.module("lePosts", ["ionic"]); lePosts.service("lePostsSvc", ["$http", "$rootScope", lePostsSvc]); lePosts.controller("lePostsCtrl", ["$scope", "$sce", "$ionicLoading", "$ionicListDelegate", "$ionicPlatform", "lePostsSvc", lePostsCtrl]); function lePostsCtrl($scope, $sce, $ionicLoading, $ionicListDelegate, $ionicPlatform, lePostsSvc) { $ionicLoading.show({template: "Loading blogs..."}); $scope.deviceReady = false; $ionicPlatform.ready(function() { $scope.$apply(function() { $scope.deviceReady = true; }); }); $scope.blogs = []; $scope.params = {}; $scope.$on("lePosts.blogs", function(_, result) { result.posts.forEach(function(b) { $scope.blogs.push({ name: b.author.name, avatar_URL: b.author.avatar_URL, title: $sce.trustAsHtml(b.title), URL: b.URL, excerpt: $sce.trustAsHtml(b.excerpt), featured_image: b.featured_image }); }); Here is the edited file. Its big, so, it continue in the next slide. Use this.
  • 10. 10 Step by Step – 4.1 – Edit the app.js file - cont $scope.$broadcast("scroll.infiniteScrollComplete"); $scope.$broadcast("scroll.refreshComplete"); $ionicLoading.hide(); }); $scope.loadMore = function() { lePostsSvc.loadBlogs($scope.params); } $scope.reload = function() { $scope.blogs = []; $scope.params = {}; lePostsSvc.loadBlogs(); } $scope.show = function($index) { cordova.InAppBrowser.open($scope.blogs[$index].URL, "_blank", "location=no"); } $scope.share = function($index) { $ionicListDelegate.closeOptionButtons(); window.socialmessage.send({ url: $scope.blogs[$index].URL }); } } function lePostsSvc($http, $rootScope) { this.loadBlogs = function(params) { $http.get("https://public-api.wordpress.com/rest/v1.1/sites/jmmwrite.wordpress.com/posts/", { params: params}) .success(function(result) { $rootScope.$broadcast("lePosts.blogs", result); }); } } Here is the edited file continuation. Take care to copy and paste and do not loose any piece of code.
  • 11. 11 Step by Step – A pause to explanations... So far we: ● Created a new project ● Edited the index page that will hold the list of blogs. There, we set up the Controller that will make the magic. See that we have a FOR loop to list the posts. We also created a functionality to reload blogs when user pull text and load more when user scroll down. ● In the controller, we created a service that connect to the wordpress feed and put the results in the array called blogs. ● You can separate controller and services in more files to organize your code.
  • 12. 12 Step by Step – 5 – Testing at your browser ● Now, in the command line, got to your app folder root, in my case: [~/workspaceIonic/lePosts]$ pwd /home/julianom/workspaceIonic/lePosts ● Run the command: ionic serve Test now.
  • 13. 13 Step by Step – 5.1 – Testing at your browser ●With the following command, you can test simulating a phone appearance: ionic serve --lab Test now.
  • 14. 14 Step by Step – TIP ● At your browser, ALWAYS run taking a look in the Console, it can help you to find errors, for example:
  • 15. 15 Step by Step – TIP 2 ● When you change html, js, css, Ionic Serve will reload it, and you just need to reload the page at your browser. In some cases this will not work properly, so, its better close Ionic Serve (type q in the console), and start again.
  • 16. 16 Step by Step – 6 – Testing in the Phone ● First of all, you need to add Platform, in my case, Android. Run the command (inside your app folder): ionic platform add android
  • 17. 17 Step by Step – 6 – Testing in the Phone ● Then, in order to run, you need to have your environment OK. Remember to perform the installations from the previous slides. In my case, I have started genymotion, then, I run the command: ionic run android
  • 18. 18 Step by Step – Exercises 1- We have a Bug in the project: ● When pulling up, app load more blogs entries, but it repeat the entries! How to solve? 2- When user click URL, you should open it ;)
  • 19. 19 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/ ● Example with Google Maps http://codepen.io/ionic/pen/uzngt ● Interesting Article about IOs native dev migration to Ionic https://www.airpair.com/javascript/posts/switching-from-ios-to-ionic ● How to deploy to App Store https://medium.com/@_qzapaia/deploy-an-ionic-app-to-the-ios-app-store-702c79a2dd97 ● SQLite example ● https://blog.nraboy.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/
  • 20. 20 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!