The Ionic Advantage
The Ionic Advantage
The Ionic Advantage
1) Navigation stack for ionic has router encapsulated and is easier to use, Inbuilt side
menu or Hamburger menu navigation.
2) UI Themes are based on the platform, ionic renders for iOS, Android and Windows
based on the themes and style of the platform.
3) Seamless integration to Angular and Cordova, uses gulp, Typescript and SASS for css
compilation, which is more or less same to what we are using.
4) Aggressive caching for screen navigation, virtual list controls for scrolling extremely
long list.
5) Offers a wide variety of customization to elementary controls and provides new
controls.
6) Angular can also be used when needed.
7) Ionic Native is a TypeScript wrapper for Cordova/PhoneGap plugins that make
adding any native functionality you need to your Ionic mobile app easy. Requires
ionic Appflow login may be licensed
8) Deploy push your apps in real time , it is paid https://ionicframework.com/docs/appflow/deploy/
9) Generate icons and splash screens for all devices and device sizes with a single
command: ionic cordova resources. This alone saves you at least a day of image
preparing for various sizes.
share your Ionic apps with clients, customers, and testers all around the world without ever going
through the App Store with ionic upload
cd helloWorld
ionic serve
Note: Error’s are shown in the browser without the need of inspect when we perform ionic
serve and when the error is resolved it shows the progress in the browser as well.
we can run the app for Cordova and ionic from the same directory and it will be easier to debug
as ionic serve can let us host the content from same directory, we do not have to install plugin
again and again to check the html or typescript errors.
Project Structure
Index.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Ionic App</title>
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-
scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<!-- cordova.js required for cordova apps (remove if not needed) -->
<script src="cordova.js"></script>
</head>
<body>
<!-- Ionic's root component and where the app will load -->
<ion-app></ion-app>
<!-- The main bundle js is generated during the build process -->
<script src="build/main.js"></script>
</body>
</html>
app.component.ts
app.html
<ion-nav [root]="rootPage"></ion-nav>
app.module.ts
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
platformBrowserDynamic().bootstrapModule(AppModule);
pages
home.html
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
The world is your oyster.
<p>
If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a>
will be your guide.
</p>
</ion-content>
Home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
}}
Command line:-
To run ionic from command line
In project directory
Typing ionic will list other set of command required for project
Ionic cordova platform – will add the cordova support to the project
{Need to connect to open network, as proxy issues are seen here}
Important points:-
1) Default ionic uses scss
2) Folder theme has variables.scss to style globally
3) Ionic.config.json contains basic ionic configuration for the ionic app
4) Resources folder contains media for icons and splash screens
Known to us from cordova projects
5) Tsconfig.json is for typescript configuration
6) Config.xml is for cordova
7) Package.json is for angular packages
8) Ionic loads icons based on platform
If we run ionic cordova run browser and then choose android as emulator we see a different
theme of buttons and if we choose iOS and refresh we see a different theme of buttons.
if we use NavController then the navigation can be done with a simple call to the push method and this
will push the page into the stack and navigate, the routing mechanism is encapsulated.
</ion-menu>
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav:Nav;
goToTournaments(){
this.nav.push(TournamentsPage);
}
navigateBack(){
this.navCtrl.pop();
<ion-header>
<ion-navbar>
<ion-title>Tournaments</ion-title>
</ion-navbar>
</ion-header>
<ion-tabs>
<ion-tab tabTitle="Team" [root]="teamDetailTab" tabIcon="basketball"></ion-tab>
<ion-tab tabTitle="Standings" [root]="standingsTab" tabIcon="podium"></ion-tab>
</ion-tabs>
To pass a parameter to the tab while navigating to the tabs bind data to rootParams
Tabs are inside their own navigation stack as an ionic application can have multiple navigation stack
<ion-tabs>
<ion-tab tabTitle="Team" [root]="teamDetailTab" [rootParams]="team"
tabIcon="basketball"></ion-tab>
<ion-tab tabTitle="Standings" [root]="standingsTab" [rootParams]="team"
tabIcon="podium"></ion-tab>
</ion-tabs>
<ion-header>
<ion-navbar color="primary">
<ion-title>{{team.name}}</ion-title>
<ion-buttons end>
<button ion-button icon-only (click)="goHome()">
<ion-icon name="home"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
popToRoot() method takes us to the home page.
goHome() {
this.navCtrl.popToRoot();
}
<ion-header>
</ion-header>
Inside a tab if we have to go to a root page, we have to call the parents popToRoot method.
Generating a provider
https://ionicframework.com/docs/native/
class MyComponentOrService {
platform.ready().then(() => {
// to stop watching
watch.unsubscribe();
});
Spent way too long diagnosing an issue only to realize a plugin wasn’t firing or installed?
Ionic Native lets you know what the issue is and how you can resolve it.
Installation
To add Ionic Native to your app, run following command to install the core package:
Note that Ionic Native core package is included by default with every Ionic app.
Usage
Install the Ionic Native package for each plugin you want to add.
For example, if you want to install the Camera plugin, you will need to run the following
command:
For example:
follow the installation instructions on each plugin’s documentation, as some plugins require
...
...
@NgModule({
...
providers: [
...
Camera
...
...
})
<ion-list>
<ion-item *ngFor="let game of games">
{{game.opponent}}
</ion-item>
</ion-list>
<ion-list>
<ion-icon name="star"></ion-icon>
{{item.team.name}}
</button>
</ion-list>
https://ionicframework.com/docs/ionicons
The grid system in ionic is extremely useful it is based on flex box, its similar to implementation in
bootstrap.