Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
84 views14 pages

Ionic Tutorial

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

Ionic Tutorial

For Cross‐Platform Mobile Software Development


About

This Tutorial is for setting up a basic hybrid mobile application using the Ionic framework. The setup will
be shown for both Mac and PC computers using a virtual Android device.

Step 1: NodeJS

The first step requires us to download and install NodeJS. These steps differ on a Mac and PC. Here is
how we install NodeJS on both machine types:

Mac requirements:

Download and install Xcode (https://itunes.apple.com/us/app/xcode/id497799835?mt=12).


Xcode is used for testing, running, and deploying IOS apps. Xcode can only be used on a Mac.

Next, we need to download and install Homebrew. Open a terminal and type:

This will automatically install Homebrew. Homebrew will help us install NodeJS, which helps us
install Ionic’s dependencies.

Next, we need to install NodeJS. Type

at the command line and hit enter.

PC requirements:

Go to NodeJS’s website ( https://nodejs.org/en/ ) and download the version of NodeJS that best
fits your machine (32 or 64 bit).
This will download an installer. Open the installer and use the default settings

Step 2: Ionic‐Cordova
Open up a terminal. Type npm install ‐g cordova ionic and hit enter.

This uses NodeJS’s package manager to install all the dependencies that Ionic needs to run. It also
installs all of Cordova’s dependencies. Cordova builds the application from your JavaScript source code
into IOS, Android, or Windows phone applications.

Step 3: Create an App from a template

Create a new folder somewhere on your computer called IonicProjects. This directory is just to hold any
and all of your IonicProjects as you develop. Open a terminal in this new directory.

We now have 3 options. We can create a blank app from no template, create an app with 3 tabs at the
bottom for different pages, or an app with a side menu with 3 sample pages. For our example, we will
use the tabs template. At your terminal, type “ionic start walkthroughApp tabs”. When prompted, type
“y” so we can build for IOS and Android with Cordova:

It will take some time for this command to run. When it is done, it will have generated a new folder
called “walkthroughApp”, which you should change directory into:

Pick your favorite text editor or IDE to open the project folder “walkthroughApp”. For this tutorial, I will
be using Atom, which can be downloaded at https://atom.io/. Whichever text editor you use, open the
file src/pages/home/home.html:
Change the contents of the home page to simply say “Hello World!”
Next, I will show you how to run the app we created.

Step 4: Set up Android Studios and Virtual Device

In order to run your app, we need a device. If you are using a Mac and have an Iphone, you can deploy it
on your actual phone using Xcode. If you have an Android device, you can deploy it on your actual
phone with Android Studios on both Mac and PC. For this tutorial, we will use a virtual Android device
on a PC. Details on the other deployment methods can be found here:
https://ionicframework.com/docs/intro/deploying/.

To start, let’s download Android Studios ( https://developer.android.com/studio/index.html ):


The screen for Mac will look slightly different, but the process is similar. Download the file and then run
the Installer.

Click through the Installer


Use the default settings. Note: Android Studio will take up a lot of space on your machine.

Agree to the terms.

Use the default locations for the program files.


Next, we need to create a virtual device. Open Android Studio and on the top bar select Tools ‐>
Android‐>AVD Manager

Next, select the Create Virtual Device Button


Next, select the Nexus 5X

Select the newest version and download it


It will take a minute or two to download
When the download is complete, click Finish. Click on the Image you just downloaded and use the
default settings. Don’t forget to give your Device a name before clicking finish again.
Step 6: Run the App

Finally! We are able to build and run the app. Open a terminal in your IonicProjects/walkThroughApp/
directory. At the terminal, type “ionic cordova emulate android ‐c ‐l ‐s”. This command builds your app
and deploys it to the virtual device that you just created. The options are as follows
‐c = console logs. Anything your print in your app will show up on the screen

‐l = enables live reload. Anytime you save changes to your code, it will reload your app with the changes

‐s = will print stack traces for your errors to your terminal

This command will take some time. After it executes, your emulator should start and our Hello World
homepage should be visible:
And that’s it! That’s all it takes to get a sample app up and running on a virtual device. To start coding
with Ionic, you need to start learning Angular2 and NodeJS.

For NodeJS, here is a link to a tutorial: https://www.tutorialspoint.com/nodejs/. NodeJS is used as the


backend for your apps. You can create a database or a RESTful API very quickly after mastering the
basics of NodeJS

For Angular 2, here is a link to a tutorial: https://www.tutorialspoint.com/angular2/. Angular 2 is used


for the frontend for your apps. It is used to respond to events in your HTML such as button clicks and
page changes.

(Prepared by Spencer Gray)

You might also like