Ionic Cheat Sheet

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A compact reference for the Ionic and Capacitor essentials used by the Trailhead example (com.example.trailhead). Baseline: Ionic Framework 9.0.10, Ionic CLI 7.2.1, Capacitor 8.6.0, Angular 22.2.5 with standalone components and signals, Node 22+. For explanations see the pages listed at the end.

Download the Ionic Cheat Sheet (PDF)

CLI Commands

Command Purpose

npm install -g @ionic/cli

Install the Ionic CLI

ionic start trailhead tabs --type=angular

Scaffold a project from a starter

ionic serve

Run in the browser with live reload

npx ng build --configuration production

Production web build

npx cap add android / npx cap add ios

Create the native projects

npx cap sync

Copy web build and config, update plugins

npx cap copy

Copy web build and config only

npx cap open android / npx cap open ios

Open Android Studio or Xcode

npx cap run android

Build and run on a device or emulator

npx cap doctor

Check the environment and plugin versions

npx cap migrate

Upgrade Capacitor to a new major version

npx capacitor-assets generate

Generate icons and splash screens

Project Layout

Path Contents

src/app/

Standalone components, services, routes

src/theme/variables.scss

Ionic theme variables

src/global.scss

Global styles and Ionic CSS imports

capacitor.config.ts

appId, appName, webDir, server, plugins

android/, ios/

Native projects, committed to Git

www/

Web build output (webDir)

Components

Component Use

ion-app, ion-router-outlet

Root and page outlet

ion-header, ion-toolbar, ion-title

Page header

ion-content

Scrollable body, handles safe areas

ion-list, ion-item, ion-label

Lists and rows

ion-searchbar

Search input (Trailhead trail search)

ion-button, ion-fab, ion-icon

Actions and icons

ion-tabs, ion-tab-bar, ion-tab-button

Tab navigation

ion-modal, ion-alert, ion-toast

Overlays

ion-refresher, ion-infinite-scroll

Pull to refresh, paging

Import each from @ionic/angular/standalone into the component’s imports array and register icons with addIcons() from ionicons.

Theming

Variable Effect

--ion-color-primary

Primary colour (plus -rgb, -contrast, -shade, -tint)

--ion-background-color

App background

--ion-text-color

Default text colour

--ion-font-family

App font

--ion-safe-area-top

Safe-area inset exposed by Ionic

--background, --color

Per-component custom properties

Dark mode comes from importing one of Ionic’s dark palette stylesheets or from prefers-color-scheme. Mode (ios or md) follows the platform unless overridden in provideIonicAngular({ mode: 'md' }).

Routing and Lifecycle

Item Notes

provideRouter(routes)

Register routes in app.config.ts

loadComponent: () => import(...)

Lazy-load a page

NavController, routerLink

Programmatic and declarative navigation

ionViewWillEnter

Page about to show; refresh data here

ionViewDidEnter

Page fully shown

ionViewWillLeave, ionViewDidLeave

Page hiding or hidden

ngOnInit

Runs once; cached pages do not re-run it

Plugins

Plugin Example

@capacitor/camera 8.2.6

Camera.getPhoto({ resultType: CameraResultType.Uri })

@capacitor/geolocation 8.2.4

Geolocation.getCurrentPosition()

@capacitor/network 8.0.1

Network.addListener('networkStatusChange', cb)

@capacitor/app 8.1.2

App.addListener('appUrlOpen', cb)

@capacitor/haptics 8.0.2

Haptics.impact()

@capacitor/splash-screen 8.0.2

SplashScreen.hide()

After installing a plugin run npx cap sync, then declare permissions in AndroidManifest.xml and Info.plist. Wrap plugins in services so tests can replace them.

Storage

Need Use

Small settings

@capacitor/preferences 8.0.1: Preferences.set and Preferences.get

Files and photos

@capacitor/filesystem 8.1.5

Relational data

@capacitor-community/sqlite

Structured browser data

IndexedDB

Tokens

Keychain and Keystore backed plugin

Build and Release

Command Result

cd android && ./gradlew assembleRelease

Release APK

cd android && ./gradlew bundleRelease

Release AAB for Google Play

Xcode: Product, Archive

iOS archive for TestFlight

versionCode / versionName

Android build and marketing version

CFBundleVersion

iOS build number

@capacitor/live-updates 0.5.0

Optional over-the-air web updates

Testing

Command Purpose

npx ng test

Unit and component tests

npx playwright test

Browser end-to-end tests (Playwright 1.65.0)

chrome://inspect

Debug the Android WebView

Safari Develop menu

Debug the iOS WebView