Angular Navigation Drawer (ナビゲーション ドロワー) コンポーネントの概要
Ignite UI for Angular Navigation Drawer コンポーネントはサイド ナビゲーション コンテナーです。コンテンツの上からスライドインまたはスライドアウト、もしくはコンテンツ内で展開/縮小するためにピン固定できます。ミニ バージョンが閉じている場合もナビゲーションへのクイック アクセスを提供します。Navigation Drawer はレスポンシブ モード選択およびタッチ ジェスチャをサポートします。コンテンツは、デフォルトのメニュー項目スタイル設定を使用する他、カスタマイズも可能です。
Angular Navigation Drawer の例
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import {
IgxButtonModule,
IgxIconModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
} from "igniteui-angular";
import { NavDrawerSimpleComponent } from "./nav-drawer-simple/nav-drawer-simple.component";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NavDrawerSimpleComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxIconModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { Component, ViewChild } from '@angular/core';
import { IgxNavigationDrawerComponent } from 'igniteui-angular';
@Component({
selector: 'app-nav-drawer-simple',
styleUrls: ['./nav-drawer-simple.component.scss'],
templateUrl: './nav-drawer-simple.component.html'
})
export class NavDrawerSimpleComponent {
@ViewChild(IgxNavigationDrawerComponent, { static: true })
public drawer: IgxNavigationDrawerComponent;
public navItems = [
{ name: 'account_circle', text: 'Avatar' },
{ name: 'error', text: 'Badge' },
{ name: 'group_work', text: 'Button Group' }
];
public selected = 'Avatar';
public navigate(item) {
this.selected = item.text;
this.drawer.close();
}
}
ts
<div class="content-wrap">
<igx-nav-drawer id="navigation" #drawer [isOpen]="true" [pinThreshold]="5000">
<ng-template igxDrawer>
<nav>
<span igxDrawerItem [isHeader]="true">Components</span>
<span *ngFor="let item of navItems" igxDrawerItem [active]="item.text === selected" igxRipple (click)="navigate(item)">
<igx-icon family="material">{{ item.name }}</igx-icon>
<span>{{ item.text }}</span>
</span>
</nav>
</ng-template>
</igx-nav-drawer>
<main>
<span igxButton="icon" igxToggleAction="navigation">
<igx-icon family="material">menu</igx-icon>
</span>
<h5>{{selected}} content.</h5>
</main>
</div>
html
.content-wrap {
display: flex;
height: 100%;
}
main {
height: 100%;
overflow: auto;
padding: 16px;
h5 {
padding: 8px 0;
}
}
:host {
display: block;
height: 100%;
}
scss
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Ignite UI for Angular Navigation Drawer を使用した作業の開始
Ignite UI for Angular Navigation Drawer コンポーネントを使用した作業を開始するには、Ignite UI for Angular をインストールする必要があります。既存の Angular アプリケーションで、以下のコマンドを入力します。
ng add igniteui-angular
cmd
Ignite UI for Angular については、「はじめに」トピックをご覧ください。
はじめに、app.module.ts ファイルに IgxNavigationDrawerModule
をインポートします。
...
import { HammerModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { IgxNavigationDrawerModule } from 'igniteui-angular';
@NgModule({
...
imports: [..., BrowserAnimationsModule, HammerModule, IgxNavigationDrawerModule],
...
})
export class AppModule {}
typescript
あるいは、16.0.0
以降、IgxNavigationDrawerComponent
をスタンドアロンの依存関係としてインポートすることも、IGX_NAVIGATION_DRAWER_DIRECTIVES
トークンを使用してコンポーネントとそのすべてのサポート コンポーネントおよびディレクティブをインポートすることもできます。
import { HammerModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgFor } from '@angular/common';
import { IGX_NAVIGATION_DRAWER_DIRECTIVES, IgxRippleDirective, IgxIconComponent } from 'igniteui-angular';
@Component({
selector: 'app-home',
template: `
<div class="content-wrap">
<igx-nav-drawer [isOpen]="true">
<ng-template igxDrawer>
<nav>
<span igxDrawerItem [isHeader]="true">Components</span>
<span
*ngFor="let item of navItems"
igxDrawerItem
[active]="item.text === selected"
igxRipple
(click)="navigate(item)"
>
<igx-icon fontSet="material">{{ item.name }}</igx-icon>
<span>{{ item.text }}</span>
</span>
</nav>
</ng-template>
</igx-nav-drawer>
<main>
<!-- app content -->
</main>
</div>
`,
styleUrls: ['home.component.scss'],
standalone: true,
imports: [BrowserAnimationsModule, HammerModule, IGX_NAVIGATION_DRAWER_DIRECTIVES, IgxRippleDirective, IgxIconComponent, NgFor],
})
export class HomeComponent {
public navItems: Product[];
}
typescript
Ignite UI for Angular Navigation Drawer モジュールまたはディレクティブをインポートしたので、igx-nav-drawer
コンポーネントの使用を開始できます。
Angular Navigation Drawer の使用
依存関係をインポートした後、Navigation Drawer をコンポーネントのテンプレートで定義できます。
<igx-nav-drawer id="navdrawer" [isOpen]="true">
</igx-nav-drawer>
html
Drawer のコンテンツを igxDrawer
ディレクティブでデコレートした <ng-template>
で設定します。
任意のコンテンツをテンプレートに設定できますが、igxDrawerItem
ディレクティブ (項目のスタイルを参照) が定義済みのスタイル設定を項目に適用します。
このディレクティブに 2 つの @Input
プロパティがあります。
active
- 項目を選択済みとしてスタイル設定します。
isHeader
- 項目をグループ ヘッダーとしてスタイル設定します。active に設定できません。
igxRipple
ディレクティブは使用感を向上します。
<div class="content-wrap">
<igx-nav-drawer id="navigation" #drawer [isOpen]="true">
<ng-template igxDrawer>
<nav>
<span igxDrawerItem [isHeader]="true">Components</span>
<span *ngFor="let item of navItems" igxDrawerItem [active]="item.text === selected" igxRipple (click)="navigate(item)">
<igx-icon fontSet="material">{{ item.name }}</igx-icon>
<span>{{ item.text }}</span>
</span>
</nav>
</ng-template>
</igx-nav-drawer>
<main>
</main>
</div>
html
igxDrawerMini
ディレクティブでデコレートした追加のテンプレートを閉じた状態の代わりの Mini バリアントとして提供できます。
Navigation Drawer はコンテンツの上にフローティングさせるか、隣に固定配置できます。デフォルトでは、ドロワーはビューポートのサイズに応じてこれらのモードを切り替えます。詳細はモードを参照してください。
モードの間に切り替えるため、2 つのコンテンツ セクションの周りに簡易なラッパーを以下のようにスタイルできます。
.content-wrap {
width: 100%;
height: 100%;
display: flex;
}
css
Navigation drawer に要素を追加して選択するためには、typescript ファイルを次のようにします。
@Component({...})
export class AppComponent {
public navItems = [
{ name: 'account_circle', text: 'Avatar' },
...
];
public selected = 'Avatar';
public navigate(item) {
this.selected = item.text;
}
}
ts
Drawer を開く/閉じる方法が複数あります。入力プロパティをアプリケーション状態にバインドするか、@ViewChild(IgxNavigationDrawerComponent)
参照を使用してコンポーネントの API へコードでアクセス、あるいはこのような場合では #drawer
テンプレート参照変数を使用できます。
<button (click)="drawer.toggle()">Menu</button>
html
Navigation Drawer は igxNavigationService
とも統合し、igxToggleAction
ディレクティブで id によって対象にされます。
app.component.html の <main>
を以下のコードと置き換えます。トグルをスタイル設定するために igxIconButton
および Icon コンポーネントを追加します。
<main>
<span igxIconButton="flat" igxToggleAction="navigation">
<igx-icon fontSet="material">menu</igx-icon>
</span>
</main>
html
また、ドロワーから項目を選択した際にドロワーを閉じる場合は、次のように @ViewChild(IgxNavigationDrawerComponent)
参照を使用できます。
import { Component, ViewChild } from '@angular/core';
import { IgxNavigationDrawerComponent } from 'igniteui-angular';
@Component({...})
export class AppComponent {
@ViewChild(IgxNavigationDrawerComponent, { static: true })
public drawer: IgxNavigationDrawerComponent;
public navigate(item) {
this.selected = item.text;
this.drawer.close();
}
}
ts
すべて適切に設定できると、ブラウザ上でデモサンプルを確認することができます。
モード
ピン固定されていないモード (コンテンツの上に配置) は標準の動作です。Drawer は上に配置され、すべてのコンテンツの上に暗いオーバーレイを適用します。モバイル デバイスで使用される一時的なナビゲーションを提供するために使用されます。
より大きい画面に Drawer をピン固定すると、相対的な位置を使用して通常のコンテンツ フローで配置されます。アプリケーションに Drawer を切り替える方法を提供するかどうかにより、ピン固定モードを使用して、確定または永続的な動作を実装できます。
Navigation Drawer はデフォルトでレスポンシブです。画面サイズに基づいて固定解除および固定モード間で切り替わります。この動作は pinThreshold
プロパティによって制御され、falsy 値 (0 など) を設定すると無効になります。
ピン固定 (persistent) モード
ピン固定は、コンテンツと同じフローに配置するために、Drawer の位置を fixed
から relative
に変更します。従って、このモードで Drawer を切り替える必要がある場合、アプリケーションのスタイル設定を切り替えるためにレイアウトをデザインする必要があります。流動レイアウトを実装するには、igxLayout
および igxFlex
ディレクティブを使用します。
上記の例に適用すると以下のようになります。
<div class="content-wrap" igxLayout igxLayoutDir="row">
<igx-nav-drawer id="navigation" #drawer [isOpen]="true" [pin]="true" [pinThreshold]="0">
</igx-nav-drawer>
<main igxFlex>
</main>
</div>
html
.content-wrap {
width: 100%;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
css
結果は以下のようになります。
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import {
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
} from "igniteui-angular";
import { NavDrawerPinComponent } from "./nav-drawer-pin/nav-drawer-pin.component";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NavDrawerPinComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { Component } from '@angular/core';
@Component({
selector: 'app-nav-drawer-pin',
styleUrls: ['./nav-drawer-pin.component.scss'],
templateUrl: './nav-drawer-pin.component.html'
})
export class NavDrawerPinComponent {
public navItems = [
{ name: 'account_circle', text: 'Avatar' },
{ name: 'error', text: 'Badge' },
{ name: 'group_work', text: 'Button Group' }
];
public selected = 'Avatar';
public navigate(item) {
this.selected = item.text;
}
}
ts
<div class="content-wrap" igxLayout>
<igx-nav-drawer id="navigation" #drawer [isOpen]="true" [pin]="true" [pinThreshold]="0">
<ng-template igxDrawer>
<nav>
<span igxDrawerItem [isHeader]="true">Components</span>
<span *ngFor="let item of navItems" igxDrawerItem [active]="item.text === selected" igxRipple (click)="navigate(item)">
<igx-icon family="material">{{ item.name }}</igx-icon>
<span>{{ item.text }}</span>
</span>
</nav>
</ng-template>
</igx-nav-drawer>
<main igxFlex>
<span igxButton="icon" igxToggleAction="navigation">
<igx-icon family="material">menu</igx-icon>
</span>
<h5>{{selected}} content.</h5>
</main>
</div>
html
.content-wrap {
display: flex;
height: 100%;
}
main {
height: 100%;
overflow: auto;
padding: 16px;
h5 {
padding: 8px 0;
}
}
:host {
display: block;
height: calc(100% - 56px);
}
scss
Drawer は flex-basis
をホスト要素に適用すると、残りのコンテンツが残りの幅に合わせます。
代わりに、ディレクティブを使用せずに以下の手動的なスタイルを適用できます。
.main {
position: absolute;
display: flex;
flex-flow: row nowrap;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
}
.main > * {
width: 100%;
}
css
ミニ バリアント
ミニ バリアントを使用する場合、Navigation Drawer を閉じる代わりに幅を変更します。
サイドでクイック選択を利用可能にするためにアイコンが常に表示されます。
このバリアントを使用するには、igxDrawerMini
ディレクティブでデコレートしたミニ テンプレートを設定します。
通常、ミニ バリアントが persistent セットアップで使用されるため、pin
を設定し、レスポンシブしきい値を無効にしました。
<igx-nav-drawer id="navigation" [pin]="true" [pinThreshold]="0">
<ng-template igxDrawer>
<span *ngFor="let item of navItems" igxDrawerItem [active]="item.text === selected" igxRipple (click)="navigate(item)">
<igx-icon fontSet="material">{{ item.name }}</igx-icon>
<span>{{ item.text }}</span>
</span>
</ng-template>
<ng-template igxDrawerMini>
<span *ngFor="let item of navItems" igxDrawerItem [active]="item.text === selected" igxRipple (click)="navigate(item)">
<igx-icon fontSet="material">{{ item.name }}</igx-icon>
</span>
</ng-template>
</igx-nav-drawer>
html
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import {
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
} from "igniteui-angular";
import { NavDrawerMiniComponent } from "./nav-drawer-mini/nav-drawer-mini.component";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NavDrawerMiniComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { Component } from '@angular/core';
@Component({
selector: 'app-nav-drawer-mini',
styleUrls: ['./nav-drawer-mini.component.scss'],
templateUrl: './nav-drawer-mini.component.html'
})
export class NavDrawerMiniComponent {
public navItems = [
{ name: 'account_circle', text: 'Avatar' },
{ name: 'error', text: 'Badge' },
{ name: 'group_work', text: 'Button Group' }
];
public selected = 'Avatar';
public navigate(item) {
this.selected = item.text;
}
}
ts
<div class="content-wrap" igxLayout>
<igx-nav-drawer id="navigation" [pin]="true" [pinThreshold]="0">
<ng-template igxDrawer>
<span *ngFor="let item of navItems" igxDrawerItem [active]="item.text === selected" igxRipple (click)="navigate(item)">
<igx-icon family="material">{{ item.name }}</igx-icon>
<span>{{ item.text }}</span>
</span>
</ng-template>
<ng-template igxDrawerMini>
<span *ngFor="let item of navItems" igxDrawerItem [active]="item.text === selected" igxRipple (click)="navigate(item)">
<igx-icon family="material">{{ item.name }}</igx-icon>
</span>
</ng-template>
</igx-nav-drawer>
<main igxFlex>
<span igxButton="icon" igxToggleAction="navigation">
<igx-icon family="material">menu</igx-icon>
</span>
</main>
</div>
html
.content-wrap {
display: flex;
height: 100%;
}
main {
height: 100%;
overflow: auto;
padding: 16px;
}
:host {
display: block;
height: 100%;
}
scss

Angular Router の使用
Angular Router を使用するには、最初に @angular/router
から git をインポートし、コンストラクターでルーターのインスタンスを作成する必要があります。次に、リンク値にルーターを使用して、ナビゲーション項目を定義します。
...
export class AppComponent {
public componentLinks = [
{
link: 'avatar',
name: 'Avatar'
},
{
link: 'badge',
name: 'Badge'
},
{
link: 'button-group',
name: 'Button Group'
}
];
}
typescript
テンプレート変数に割り当てられている routerLinkActive
を使用でき、その isActive
プロパティを使用して、igxDrawerItem
の active
入力にバインドできます。<igx-nav-drawer>
テンプレートは以下のようになります。
/* app.component.html */
<ng-template igxDrawer>
<nav>
<span igxDrawerItem [isHeader]="true">Components</span>
<span
*ngFor="let item of componentLinks"
routerLink="{{item.link}}"
routerLinkActive
#rla="routerLinkActive"
igxDrawerItem
igxRipple
[active]="rla.isActive">
{{item.name}}
</span>
</nav>
</ng-template>
html
最後に、app.module.ts
ファイルに項目のルートと共に RouterModule をインポートします。
import { RouterModule } from '@angular/router';
@NgModule([
imports: [
RouterModule,
RouterModule.forRoot([
{path: 'avatar', component: NavDrawerRoutingComponent},
{path: 'badge', component: NavDrawerRoutingComponent},
{path: 'button-group', component: NavDrawerRoutingComponent}
])
]
])
ts
上記の手順が完了した後に、アプリは以下のようになります。
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import {
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
} from "igniteui-angular";
import { NavDrawerRoutingComponent } from "./nav-drawer-routing/nav-drawer-routing.component";
import { RouterModule } from "@angular/router";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NavDrawerRoutingComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule,
RouterModule.forRoot([
{path: "avatar", component: NavDrawerRoutingComponent},
{path: "badge", component: NavDrawerRoutingComponent},
{path: "button-group", component: NavDrawerRoutingComponent}
])
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { Component } from '@angular/core';
@Component({
selector: 'app-nav-drawer-routing',
styleUrls: ['./nav-drawer-routing.component.scss'],
templateUrl: './nav-drawer-routing.component.html'
})
export class NavDrawerRoutingComponent {
public componentLinks = [
{
link: 'avatar',
name: 'Avatar'
},
{
link: 'badge',
name: 'Badge'
},
{
link: 'button-group',
name: 'Button Group'
}
];
}
ts
<div class="content-wrap">
<igx-nav-drawer id="navigation" #drawer [isOpen]="true">
<ng-template igxDrawer>
<nav>
<span igxDrawerItem [isHeader]="true">Components</span>
<span
igxDrawerItem
igxRipple
*ngFor="let item of componentLinks"
routerLink="{{item.link}}"
routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive"
>
{{item.name}}
</span>
</nav>
</ng-template>
</igx-nav-drawer>
<main>
<span igxButton="icon" igxToggleAction="navigation">
<igx-icon family="material">menu</igx-icon>
</span>
</main>
</div>
html
.content-wrap {
display: flex;
height: 100%;
}
main {
height: 100%;
overflow: auto;
padding: 16px;
}
:host {
display: block;
height: 100%;
}
scss
階層ナビゲーション
IgxNavigationDrawerComponent
を使用してマルチレベル階層ナビゲーションを作成するには、igxDrawer
テンプレートの IgxTreeComponent を使用できます。ツリーはアプリケーションの Routes
オブジェクトから直接作成できます。以下はその方法です。
<igx-nav-drawer [isOpen]="true" [enableGestures]="true" width="280px">
<ng-template igxDrawer>
<igx-tree>
<igx-tree-node *ngFor="let route of routes">
<a igxTreeNodeLink [routerLink]="route.path" routerLinkActive="route-selected-class">{{ route.data?.displayName }}</a>
<igx-tree-node *ngFor="let child of route.children">
<a igxTreeNodeLink [routerLink]="[route.path, child.path]" routerLinkActive="route-selected-class">{{ child.data?.displayName }}</a>
</igx-tree-node>
</igx-tree-node>
</igx-tree>
</ng-template>
</igx-nav-drawer>
html
この例では、igxDrawerItem
を使用せずに、カスタム igxDrawer
コンテンツ (この場合は igx-tree
) を直接使用します。
import { menusRoutes } from '../../menus-routing.module';
@Component({
selector: 'app-nav-drawer-hierarchical',
templateUrl: './nav-drawer-hierarchical.component.html',
styleUrls: ['./nav-drawer-hierarchical.component.scss'],
})
export class NavDrawerHierarchicalComponent {
public routes = menusRoutes;
}
typescript
この例では、igx-tree
ノードでリンク テキストを可視化するために使用される displayName
プロパティを含むカスタム ルーティング data
でルートを生成します。以下は Route
の例です。
export const menusRoutes: Routes = [
{
component: NavDrawerHierarchicalComponent,
path: 'navigation-drawer-hierarchical',
data: { displayName: 'Hierarchical Drawer Menu' },
},
];
typescript
ルートの children
プロパティから抽出された子ルーティングもあります。このサンプルは 2 つの階層レベルを示していますが、ルーティングに複数の階層がある場合は、ツリー ノード テンプレートで 2 番目の下のレベルを定義するだけです。
空のルート リダイレクト、エラー ルート、ページが見つからないなどの一部のルートは、可視化に直接適さない場合があることに注意してください。ツリーをルーティング オブジェクトにバインドする前に、コンポーネント ロジックでオブジェクトからそれらのルートを削除できます。
以下の例は、トピック名とリンクを含む定義済みデータを使用して、階層構造の機能を示しています。この構造により、ユーザーは機能的で詳細なナビゲーションを簡単に生成し、各要素をリンクとして表示するかインジケーターとして表示するかを定義することができます。
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import {
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule,
IgxTreeModule
} from "igniteui-angular";
import { NavDrawerHierarchicalComponent } from "./nav-drawer-hierarchical/nav-drawer-hierarchical.component";
import { RouterModule } from "@angular/router";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NavDrawerHierarchicalComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule,
IgxTreeModule,
RouterModule.forRoot([
{ path: 'grid', component: NavDrawerHierarchicalComponent, data: { displayName: 'Grid' } },
{ path: 'tree-grid', component: NavDrawerHierarchicalComponent, data: { displayName: 'Tree Grid' } },
{ path: 'hierarchical-grid', component: NavDrawerHierarchicalComponent, data: { displayName: 'Hierarchical Grid' } },
{ path: 'pivot-grid', component: NavDrawerHierarchicalComponent, data: { displayName: 'Pivot Grid' } },
{ path: 'area-chart', component: NavDrawerHierarchicalComponent, data: { displayName: 'Area Chart' } },
{ path: 'bar-chart', component: NavDrawerHierarchicalComponent, data: { displayName: 'Bar Chart' } },
{ path: 'column-chart', component: NavDrawerHierarchicalComponent, data: { displayName: 'Column Chart' } },
{ path: 'pie-chart', component: NavDrawerHierarchicalComponent, data: { displayName: 'Pie Chart' } },
{ path: 'action-strip', component: NavDrawerHierarchicalComponent, data: { displayName: 'Action Strip' } },
{ path: 'dialog', component: NavDrawerHierarchicalComponent, data: { displayName: 'Dialog' } },
{ path: 'drag-drop', component: NavDrawerHierarchicalComponent, data: { displayName: 'Drag and Drop' } },
{ path: 'dock-manager', component: NavDrawerHierarchicalComponent, data: { displayName: 'Dock Manager' } },
{ path: 'expansion-panel', component: NavDrawerHierarchicalComponent, data: { displayName: 'Exspansion Panel' } },
{ path: 'layout', component: NavDrawerHierarchicalComponent, data: { displayName: 'Layout Manager' } },
{ path: 'banner', component: NavDrawerHierarchicalComponent, data: { displayName: 'Banner' } },
{ path: 'snackbar', component: NavDrawerHierarchicalComponent, data: { displayName: 'Snackbar' } },
{ path: 'toast', component: NavDrawerHierarchicalComponent, data: { displayName: 'Toast' } }
])
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { AfterViewInit, Component, ViewChild } from '@angular/core';
import { IgxTreeComponent } from 'igniteui-angular';
@Component({
selector: 'app-nav-drawer-hierarchical',
templateUrl: './nav-drawer-hierarchical.component.html',
styleUrls: ['./nav-drawer-hierarchical.component.scss']
})
export class NavDrawerHierarchicalComponent implements AfterViewInit {
@ViewChild('tree') public tree: IgxTreeComponent;
public selectedContent = 'Home';
public routes = [
{
path: 'grids', displayName: 'Grids',
children: [
{ path: 'grid', displayName: 'Data Grid' },
{ path: 'tree-grid', displayName: 'Tree Grid' },
{ path: 'hierarchical-grid', displayName: 'Hierarchical Grid' },
{ path: 'pivot-grid', displayName: 'Pivot Grid' }
]
},
{
path: 'charts', displayName: 'Charts',
children: [
{ path: 'area-chart', displayName: 'Area Chart' },
{ path: 'bar-chart', displayName: 'Bar Chart' },
{ path: 'column-chart', displayName: 'Column Chart' },
{ path: 'pie-chart', displayName: 'Pie Chart' }
]
},
{
path: 'interactions', displayName: 'Interactions',
children: [
{ path: 'action-strip', displayName: 'Action Strip' },
{ path: 'dialog', displayName: 'Dialog' },
{ path: 'drag-drop', displayName: 'Drag and Drop' }
]
},
{
path: 'layouts', displayName: 'Layouts',
children: [
{ path: 'dock-manager', displayName: 'Dock Manager' },
{ path: 'expansion-panel', displayName: 'Exspansion Panel' },
{ path: 'layout', displayName: 'Layout Manager' }
]
},
{
path: 'notifications', displayName: 'Notifications',
children: [
{ path: 'banner', displayName: 'Banner' },
{ path: 'snackbar', displayName: 'Snackbar' },
{ path: 'toast', displayName: 'Toast' }
]
}
]
constructor() { }
public ngAfterViewInit() {
this.tree.activeNodeChanged.subscribe(node => {
this.selectedContent = node.data;
})
}
}
ts
<div class="content-wrap" igxLayout>
<igx-nav-drawer #drawer [isOpen]="true" [enableGestures]="true" width="280px">
<ng-template igxDrawer>
<igx-tree #tree>
<igx-tree-node [data]="route.displayName" *ngFor="let route of routes">
{{ route.displayName }}
<igx-tree-node [data]="child.displayName" *ngFor="let child of route.children">
<a igxTreeNodeLink [routerLink]="child.path">{{ child.displayName }}</a>
</igx-tree-node>
</igx-tree-node>
</igx-tree>
</ng-template>
</igx-nav-drawer>
<main igxFlex>
<span igxButton="icon" igxToggleAction="navigation" (click)="drawer.toggle()">
<igx-icon family="material">menu</igx-icon>
</span>
<h5>{{selectedContent}}</h5>
</main>
</div>
html
.content-wrap {
display: flex;
height: 100%;
}
main {
height: 100%;
overflow: auto;
padding: 16px;
}
:host {
display: block;
height: 100%;
}
scss
スタイル設定
Navigation drawer のスタイル設定を始めるには、すべてのテーマ関数とコンポーネント ミックスインが存在する index
ファイルをインポートする必要があります。
@use "igniteui-angular/theming" as *;
scss
最も簡単な方法は、navdrawer-theme
を拡張する新しいテーマを作成し、navdrawer の項目をスタイル設定するいくつかのパラメーターを受け取る方法です。
$custom-theme: navdrawer-theme(
$background: #2d313a,
$item-active-background: #ecc256,
$item-header-text-color: #ecc256,
);
scss
ご覧のとおり、navdrawer-theme
は、アイテムの基本的なスタイル設定に役立ついくつかのパラメーターを公開しています。
最後にコンポーネントのテーマをアプリケーションに含めます。
@include css-vars($custom-theme);
scss
コンポーネントが Emulated
ViewEncapsulation を使用している場合、スタイルを適用するには ::ng-deep
を使用してこのカプセル化を解除する必要があります。
:host {
::ng-deep {
@include css-vars($custom-theme);
}
}
scss
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import {
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule
} from "igniteui-angular";
import { NavDrawerRoutingComponent } from "./nav-drawer-routing/nav-drawer-routing.component";
import { NavDrawerStylingComponent } from "./nav-drawer-styling/nav-drawer-styling.component";
import { RouterModule } from "@angular/router";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NavDrawerRoutingComponent,
NavDrawerStylingComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxIconModule,
IgxLayoutModule,
IgxNavigationDrawerModule,
IgxRippleModule,
IgxToggleModule,
RouterModule.forRoot([
{path: "avatar", component: NavDrawerRoutingComponent},
{path: "badge", component: NavDrawerRoutingComponent},
{path: "button-group", component: NavDrawerRoutingComponent}
])
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { Component } from '@angular/core';
@Component({
selector: 'app-nav-drawer-styling',
styleUrls: ['./nav-drawer-styling.component.scss'],
templateUrl: './nav-drawer-styling.component.html'
})
export class NavDrawerStylingComponent { }
ts
<app-nav-drawer-routing></app-nav-drawer-routing>
html
@use '../../variables' as *;
.content-wrap {
display: flex;
height: 100%;
}
main {
height: 100%;
overflow: auto;
padding: 16px;
h5 {
padding: 8px 0;
}
}
:host {
display: block;
height: 100%;
$custom-theme: navdrawer-theme(
$background: #2d313a,
$item-active-background: #ecc256,
$item-header-text-color: #f3c03e
);
@include css-vars($custom-theme);
}
scss
API とスタイル リファレンス