tutorial: develop mobile applications with angularjs

36
Tutorial Develop Mobile Applications with AngularJS

Upload: philipp-burgmer

Post on 09-May-2015

2.878 views

Category:

Technology


0 download

DESCRIPTION

Slides for my tutorial at Karlsruher Entwicklertag 2014. Visit us at http://www.thecodecampus.de Folien zu meinem Tutorial beim Karlsruher Entwicklertag 2014. AngularJS hat sich in den letzen 2 Jahren von einem vielversprechendem zu einem viel eingesetzten JavaScript MVC Framework entwickelt, das immer mehr an Aufmerksamkeit und Zulauf gewinnen kann. Es gibt zahlreiche kleine und auch einige große Anwendungen im Netz die auf AngularJS basieren und viele davon sind "mobile ready". Doch ist AngularJS auch eine gute Wahl um nicht nur "mobile ready" Web-Anwendungen sonder native mobile Anwendungen zu entwickeln? In diesem Tutorial wird anhand von Beispielen gezeigt wie AngularJS z.B. zusammen mit PhoneGap eingesetzt werden kann um native Anwendungen für diverse mobile Platformen mit modernen Web-Technologien zu entwickeln.

TRANSCRIPT

Page 1: Tutorial: Develop Mobile Applications with AngularJS

Tutorial

Develop Mobile Applications with AngularJS

Page 2: Tutorial: Develop Mobile Applications with AngularJS

Philipp BurgmerSoftware Engineer / Consultant / TrainerFocus: Frontend, Web Technologies

WeigleWilczek [email protected]

ABOUT ME

Page 3: Tutorial: Develop Mobile Applications with AngularJS

WeigleWilczek / W11kSoftware Design, Development & MaintenanceConsulting, Trainings & Project Kickoff

Web Applications with AngularJSNative Rich Clients with Eclipse RCP

ABOUT US

Page 4: Tutorial: Develop Mobile Applications with AngularJS

Developing Mobile ApplicationsNative Look & FeelWeb-Technologies (HTML, JavaScript, CSS)

SetupArchitectureDevelopmentAPIs

WHAT IT'S ALL ABOUT

Page 5: Tutorial: Develop Mobile Applications with AngularJS

SETUP

Page 6: Tutorial: Develop Mobile Applications with AngularJS

Installed and in Path:Node.JS - node - brew install nodeNode Package Manager - npmGit - git - brew install gitRuby - rubyCompass - compass - [sudo] gem install compass

Page 7: Tutorial: Develop Mobile Applications with AngularJS

Optional:Android SDK

developer.android.com/sdk (http://developer.android.com/sdk/index.html) or brew install androidLaunch Android SDK Manager ( android or Help (http://developer.android.com/tools/help/sdk-manager.html))Install Following Packages:

Xcode and iOS 7 Simulator on MacOS

Page 8: Tutorial: Develop Mobile Applications with AngularJS

Apache Cordova - [sudo] npm install -g cordovaIonic - [sudo] npm install -g ionic

Optional:Ripple Emulator - [sudo] npm install -g ripple-emulatoriOS Sim - [sudo] npm install -g ios-sim

Page 9: Tutorial: Develop Mobile Applications with AngularJS

ARCHITECTURE

Page 10: Tutorial: Develop Mobile Applications with AngularJS

Mobile OS

WebView

Ionic

AngularJSCordova

Application

THE BIG PICTURE

Page 11: Tutorial: Develop Mobile Applications with AngularJS

Better Known as PhoneGap (http://phonegap.com/)

Nitobi Adobe ApacheNative Wrapper for Web-AppMixing Native- and Web-CodePlugins for Feature Access

cordova.apache.org (http://cordova.apache.org/)

Current Version: 3.4.1License: Apache 2.0

Page 12: Tutorial: Develop Mobile Applications with AngularJS

229 PluginsNative JavaScript

org.apache.cordovaCameraBattery StatusConsoleContactsDevice Information + Motion + OrientationDialogsFile + File Transfer

CORDOVA PLUGINS

Page 13: Tutorial: Develop Mobile Applications with AngularJS

Distributioin of CordovaServices like PhoneGap Build

phonegap.com (http://phonegap.com/)

Developed by AdobeLicense: Apache 2.0

Page 14: Tutorial: Develop Mobile Applications with AngularJS

HTML enhanced for web apps!angularjs.org

JavaScript-Framework for Rich Browser ApplicationsBrings Core UI Concepts like MVC to BrowserExtends HTML instead of abstract itLets You Extend HTML to Your Needs (Directives)

angularjs.org (https://angularjs.org/)

Current Version: 1.2.16License: MIT

by

Page 15: Tutorial: Develop Mobile Applications with AngularJS

Frontend-FrameworkCSS Optimized for Mobile AppAngularJS Directives and Services

Touch SupportNavigationMenus & Dialogs

Cordova Plugin(s)

ionicframework.com (http://ionicframework.com/)

Current Version: 1.0.0-beta.6License: MIT

Page 16: Tutorial: Develop Mobile Applications with AngularJS

Similar to IonicFrontend-FrameworkCordova and AngularJS basedDirectives and Services

onsenui.io (http://onsenui.io/)

Current Version 1.0.4License: Apache 2.0

Page 17: Tutorial: Develop Mobile Applications with AngularJS

OUR FIRST APP

Page 18: Tutorial: Develop Mobile Applications with AngularJS

Create and Navigate to an Empty FolderRun ionic start myFirstApp tabs to Create a New Ionic ApplicationNavigate to Project Folder cd myFirstAppRun ionic serve (Ignore Error on Console)Browser to http://localhost:8100 (http://localhost:8100)

Play around with the App!Kill Dev-Server in Console with CTRL+C

Do the Same Again with ionic start mySecondApp sidemenu

HANDSON

Page 19: Tutorial: Develop Mobile Applications with AngularJS

PROJECT STRUCTURE

Cordovahooksmergesplatformspluginswwwconfig.xml

Ionicionic.project

Customscssbower.jsonGulpfile.jspackage.json

Page 20: Tutorial: Develop Mobile Applications with AngularJS

<?xml version='1.0' encoding='utf-8'?><widget id="com.ionicframework.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <name>HelloCordova</name> <description> An Ionic Framework and Cordova project. </description> <author email="hi@ionicframework" href="http://ionicframework.com/"> Ionic Framework Team </author> <content src="index.html" /> <access origin="*" /> <preference name="fullscreen" value="true" /> <preference name="webviewbounce" value="false" /> <preference name="UIWebViewBounce" value="false" /> <preference name="DisallowOverscroll" value="true" />

<!-- Don't store local date in an iCloud backup. Turn this to "cloud" to enable storage to be sent to iCloud. Note: enabling this could result in Apple rejecting your app. --> <preference name="BackupWebStorage" value="none" />

<feature name="StatusBar"> <param name="ios-package" value="CDVStatusBar" onload="true" /> </feature></widget>

CONFIG.XML

Page 21: Tutorial: Develop Mobile Applications with AngularJS

TOOLS

Page 22: Tutorial: Develop Mobile Applications with AngularJS

Required to Configure and Build Cordova Project

Run cordova to See All Available CommandsCommands to Configure ProjectCommands to Build Project

CORDOVA CLI

Page 23: Tutorial: Develop Mobile Applications with AngularJS

Ionic Consists of Two Things:Framework (also Available via Bower)Command Line Interface (via NPM)

CLI Not Required to Develop Ionic AppDifferent Versioning

Run ionic to See All Available CommandsShortcuts to Cordova CLIcreate and servelogin and upload

IONIC CLI

Page 24: Tutorial: Develop Mobile Applications with AngularJS

Node Package, Installed via npm install -g ripple-emulatorEmulates Android Device in BrowserRequires Android as PlatformStart Server and Open Browser: ripple emulate

RIPPLE EMULATOR

Page 25: Tutorial: Develop Mobile Applications with AngularJS

AndroidAndroid SDK Requiredcordova platform add android or ionic platform androidcordova emulate android or ionic emulate androidTake a Nap or Drink Some Coffee ...

iOSXcode, iOS Simulator and ios-sim Requiredcordova platform add ios or ionic platform ioscordova emulate ios or ionic emulate ios

PLATFORM SIMULATORS

Page 26: Tutorial: Develop Mobile Applications with AngularJS

Create a New Cordova Project (not Ionic)Compare Project Structure to Ionic Project (config.xml)Delete Cordova Project

Add Android Platform to Ionic Project via ionicRemove Android Platform via cordovaAdd Android Platform Again via cordova

Run ionic serve , Open App in Browser and Check Console for JS ErrorsRun Ripple Emulator and Check Console for JS ErrorsRun cordova serve , Open App in Browser and Check Console for JS Errors

HANDSON

Page 27: Tutorial: Develop Mobile Applications with AngularJS

APIS

Page 28: Tutorial: Develop Mobile Applications with AngularJS

API Documentation: docs.angularjs.org/api (https://docs.angularjs.org/api)

Pay Attention: Documentation for latest Build (Select Box at The Top Left Corner)Basic Tutorial: docs.angularjs.org/tutorial (https://docs.angularjs.org/tutorial)

Great Tutorial Videos: egghead.io (https://egghead.io/)

ANGULARJS

Page 29: Tutorial: Develop Mobile Applications with AngularJS

API Doc and Guides at ionicframework.com/docs (http://ionicframework.com/docs/)

Lot of Live Demos and Code Examples

All Directive Starts with Prefix ion (Nice!)All Services Uses $ionic Prefix (Bad Practice?)Uses Angular-UI Router

IONIC

Page 30: Tutorial: Develop Mobile Applications with AngularJS

OPTIMISATION

Page 31: Tutorial: Develop Mobile Applications with AngularJS

Avoid Overlapping Elements (Popups, Overlays)Try to Keep the DOM Small, Create Multiple Small StatesHTML Tables Are SluggishTransport Really Needed Data OnlyUse CachingMinimize CodeTest Performance on Real and Old Devices

PERFORMANCE HINTS

Page 32: Tutorial: Develop Mobile Applications with AngularJS

Subfolders in hooksSomething Executable (with Hash-Bang)See README (https://github.com/apache/cordova-lib/blob/master/cordova-lib/templates/hooks-README.md) for a List Of Available HooksCan Be Used to Build Frontend (Modify www Content)Pay Attention: No www Folder No Valid Cordova Project!

HOOKS

Page 33: Tutorial: Develop Mobile Applications with AngularJS

Helps to Structure CodeDev-Mode with Server, Proxy and LiveReloadSASS 3.2 and LESS 1.5 supportSpec and End-2-End TestMock Data for Tests and Dev-ModeRunning Bower to Install and Update Frontend DependenciesProject- and Per-Developer Configuration as well as Command Line ArgumentsBuilding Distribution with

Annotating AngularJS Dependencies (Transform to Array-Notation)Code MinimizationRunning End-2-End Tests Against Build Application

FABSFABULOUS ANGULARJS BUILD SYSTEM

Page 34: Tutorial: Develop Mobile Applications with AngularJS

Clone GitHub Repo pburgmer/et-ka-2014-ionic-tutorial-app (https://github.com/pburgmer/et-ka-2014-ionic-tutorial-app)

to Get an Ionic App with fabs as Build-SystemRun npm install in Project FolderCreate before_prepare Hook

Run Grunt Build: grunt clean prepare compileCreate a Symlink (if not exists) from build-output/compiled to wwwor Clean www and Copy Content from build-output/compiled to It

Add Android as PlatformRun cordova prepareTake a Look at platform/android/www to Ensure Minified Version Is Used

HANDSON

Page 35: Tutorial: Develop Mobile Applications with AngularJS

Philipp [email protected]

www.w11k.com (http://www.w11k.com)

www.thecodecampus.de (http://www.thecodecampus.de)

Page 36: Tutorial: Develop Mobile Applications with AngularJS