Ionic Angular Quickstart
ようこそ!このガイドでは、Ionic Angular 開発の基本を説明します。開発環境のセットアップ、シンプルなプロジェクトの生成、プロジェクト構造の探索、Ionic コンポーネントの動作方法を学びます。最初の実際のアプリを構築する前に Ionic Angular に慣れるのに最適です。
Ionic Angular とは何か、Angular エコシステムにどのように適合するかの高レベルの概要をお探しの場合は、Ionic Angular の概要を参照してください。
前提条件
始める前に、マシンに Node.js と npm がインストールされていることを確認してください。 次を実行して確認できます:
node -v
npm -v
Node.js と npm がない場合は、こちらから Node.js をダウンロードしてください(npm が含まれています)。
Ionic CLI でプロジェクトを作成
まず、最新のIonic CLIをインストールします:
npm install -g @ionic/cli
次に、次のコマンドを実行して新しいプロジェクトを作成し、実行します:
ionic start myApp blank --type angular
cd myApp
ionic serve
最初のプロンプトで、Standaloneを選択します。
ionic serveを実行すると、プロジェクトがブラウザで開きます。

Explore the Project Structure
Your new app's directory will look like this:
└── src/
└── app
├── app.component.html
├── app.component.scss
├── app.component.ts
├── app.routes.ts
└── home/
├── home.page.html
├── home.page.scss
├── home.page.spec.ts
└── home.page.ts
以下の例のすべてのファイルパスは、プロジェクトのルートディレクトリを基準にしています。
アプリの構造を理解するために、これらのファイルを見ていきましょう。
View the App Component
The root of your app is defined in app.component.ts:
import { Component } from '@angular/core';
import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
imports: [IonApp, IonRouterOutlet],
})
export class AppComponent {
constructor() {}
}
And its template in app.component.html:
<ion-app>
<ion-router-outlet></ion-router-outlet>
</ion-app>
これにより、Ionic のion-appとion-router-outletコンポーネントを使用してアプリケーションのルートが設定されます。ルーターアウトレットは、ページが表示される場所です。
View Routes
Routes are defined in app.routes.ts:
import { Routes } from '@angular/router';
export const routes: Routes = [
{
path: 'home',
loadComponent: () => import('./home/home.page').then((m) => m.HomePage),
},
{
path: '',
redirectTo: 'home',
pathMatch: 'full',
},
];
ルート URL(/)にアクセスすると、HomePageコンポーネントが読み込まれます。
View the Home Page
The Home page component, defined in home.page.ts, imports the Ionic components it uses:
import { Component } from '@angular/core';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
imports: [IonHeader, IonToolbar, IonTitle, IonContent],
})
export class HomePage {
constructor() {}
}
And the template, in the home.page.html file, uses those components:
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title> Blank </ion-title>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Blank</ion-title>
</ion-toolbar>
</ion-header>
<div id="container">
<strong>Ready to create an app?</strong>
<p>
Start with Ionic
<a target="_blank" rel="noopener noreferrer" href="https://ionicframework.com/docs/components">UI Components</a>
</p>
</div>
</ion-content>
これにより、ヘッダーとスクロール可能なコンテンツ領域を持つページが作成されます。2 番目のヘッダーは、コンテンツの上部にあるときに表示される折りたたみ可能な大きなタイトルを示し、スクロールダウンすると最初のヘッダーの小さなタイトルを表示するために縮小されます。
Ionic コンポーネントを追加
より多くの Ionic UI コンポーネントで Home ページを強化できます。たとえば、ion-contentの最後にButtonを追加します:
<ion-content>
<!-- existing content -->
<ion-button>Navigate</ion-button>
</ion-content>
Then, import the IonButton component in home.page.ts:
import { IonButton, IonContent, IonHeader, IonTitle, IonToolbar } from '@ionic/angular/standalone';
@Component({
// ...existing config...
imports: [IonButton, IonContent, IonHeader, IonTitle, IonToolbar],
})
Add a New Page
To add a new page, generate it with the CLI:
ionic generate page new
A route will be automatically added to app.routes.ts.
In new.page.html, you can add a Back Button to the Toolbar:
<ion-header [translucent]="true">
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/"></ion-back-button>
</ion-buttons>
<ion-title>new</ion-title>
</ion-toolbar>
</ion-header>
And import IonBackButton and IonButtons in new.page.ts:
import { IonBackButton, IonButtons, IonContent, IonHeader, IonTitle, IonToolbar } from '@ionic/angular/standalone';
@Component({
// ...existing config...
imports: [IonBackButton, IonButtons, IonContent, IonHeader, IonTitle, IonToolbar],
})
ion-back-buttonは、前のページへのナビゲーション、または履歴がない場合は/へのナビゲーションを自動的に処理します。
Navigate to the New Page
To navigate to the new page, update the button in home.page.html:
<ion-button [routerLink]="['/new']">Navigate</ion-button>
Then, import RouterLink in home.page.ts:
import { RouterLink } from '@angular/router';
@Component({
// ...existing config...
imports: [IonButton, IonContent, IonHeader, IonTitle, IonToolbar, RouterLink],
})
Angular の Router サービスを使用してナビゲーションを実行することもできます。詳細については、Angular Navigation ドキュメントを参照してください。