Ralph/ July 1, 2017/ Ionic, Ionic 4

Prepare Environment

Install Node.JS

nvm install $LATEST --latest-npm
node --version 
npm --version
nvm alias latest $LATEST
nvm alias default $LATEST

Install Ionic 4

npm -g install ionic@latest
ionic -version

Create an app from Template

ionic start --list
ionic start sidemenu sidemenu
ionic start super super

Introduction: First App

Prepare the base App

Create basic structure with tutorial template

ionic start app_from_scratch sidemenu --type angular
cd app_from_scratch

Some name changing

To keep the structure of the filenames the same, i like to change the name for the routing module (changing the dash to a dot)





Show base app

ionic serve -c

Add a page

Create a new page with the name “About”

ionic generate page About

Add import to app.components.ts

  public appPages = [
    { title: 'Home', url: '/home', icon: 'home' },
    { title: 'List', url: '/list', icon: 'list' },
    { title: 'About', url: '/about', icon: '' }

Add item to app-routing.module.ts

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', loadChildren: './home/home.module#HomePageModule' },
  { path: 'list', loadChildren: './list/list.module#ListPageModule' },
  { path: 'about', loadChildren: './about/about.module#AboutPageModule' }

Save the file now, and you will see the sidemenu entry:

Looks great, but… where is the sidemenu?

Ok, if you check the home page html code (home.page.html), you will find a button for the side menu

    <ion-buttons slot="start">

Missing in about.page.html:


So, we had to add the desired code snippet

      <ion-buttons slot="start">

Add some Ionic Components

Look at the Ionic Preview App, or read the documentation, if you what to dive in immediately.

Or just copy some code from the documentation page and try by yourself:


We describe the steps to add additional components in detail in this blog.

Directory structure of an application

One possible way to build an app is:

  • create a base app from blank template
  • add desired pages, code and components

To find out the necessary steps to add an new page or component, look into the templates and compare a template with the blank template. the differences are the required steps to an a component.

For example, if you want to add tabs to your app, then compare the blank template with the tabs template:

ionic start starter_tabs  tabs --type angular --no-deps --no-git --no-link
ionic start starter_blank blank --type angular --no-deps --no-git --no-link

The diff command shows the changes between the to templates:

diff -r -w starter_tabs starter_blank
diff -r -w starter_blank/ionic.config.json starter_tabs/ionic.config.json
<   "name": "starter_blank",
>   "name": "starter_tabs",
diff -r -w starter_blank/package.json starter_tabs/package.json
<   "name": "starter_blank",
>   "name": "starter_tabs",
Only in starter_tabs/src/app: about
diff -r -w starter_blank/src/app/app-routing.module.ts starter_tabs/src/app/app-routing.module.ts
<   { path: '', redirectTo: 'home', pathMatch: 'full' },
<   { path: 'home', loadChildren: './home/home.module#HomePageModule' },
>   { path: '', loadChildren: './tabs/tabs.module#TabsPageModule' }
diff -r -w starter_blank/src/app/app.module.ts starter_tabs/src/app/app.module.ts
< import { RouterModule, RouteReuseStrategy, Routes } from '@angular/router';
> import { RouterModule, RouteReuseStrategy } from '@angular/router';
< import { AppComponent } from './app.component';
> import { AppComponent } from './app.component';
Only in starter_tabs/src/app: contact
diff -r -w starter_blank/src/app/home/home.module.ts starter_tabs/src/app/home/home.module.ts
> import { IonicModule } from '@ionic/angular';
> import { RouterModule } from '@angular/router';
< import { IonicModule } from '@ionic/angular';
< import { RouterModule } from '@angular/router';
>     IonicModule,
<     IonicModule,
<     RouterModule.forChild([
<       {
<         path: '',
<         component: HomePage
<       }
<     ])
>     RouterModule.forChild([{ path: '', component: HomePage }])
diff -r -w starter_blank/src/app/home/home.page.html starter_tabs/src/app/home/home.page.html
<     <ion-title>
<       Ionic Blank
<     </ion-title>
>     <ion-title>Home</ion-title>
diff -r -w starter_blank/src/app/home/home.page.spec.ts starter_tabs/src/app/home/home.page.spec.ts
<     })
<       .compileComponents();
>     }).compileComponents();
diff -r -w starter_blank/src/app/home/home.page.ts starter_tabs/src/app/home/home.page.ts
<   styleUrls: ['home.page.scss'],
>   styleUrls: ['home.page.scss']
< export class HomePage {
< }
> export class HomePage {}
Only in starter_tabs/src/app: tabs

Some differences comes from the different names (starter_blank vs. starter_tabs, HomePage vs. TabsPage). The important changes are those, which are new in the starter_tabs directory.

Share this Post