Overlay
オーバーレイ サービスはアプリケーションの前景にコンテンツを動的な描画をサポートします。描画するコンテンツおよび描画方法 (配置、アニメーション、スクロールおよびクリック動作など) を構成できます。
このオーバーレイ サービスは Toggle ディレクティブと完全に統合されています。
Angular Overlay の例
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 {
IgxIconModule,
IgxOverlayService,
IgxCardModule
} from "igniteui-angular" ;
import { OverlaySampleMain1Component } from "./overlay-main-1/overlay-main-sample-1.component" ;
import { MyDynamicCardComponent } from "./overlay-dynamic-card/overlay-dynamic-card.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
OverlaySampleMain1Component,
MyDynamicCardComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxIconModule,
IgxCardModule
],
providers : [IgxOverlayService],
entryComponents : [MyDynamicCardComponent],
schemas : []
})
export class AppModule {}
ts コピー import { Component, Inject, OnDestroy } from '@angular/core' ;
import { IgxOverlayService } from 'igniteui-angular' ;
import { MyDynamicCardComponent} from '../overlay-dynamic-card/overlay-dynamic-card.component' ;
@Component ({
selector : 'app-overlay-sample' ,
templateUrl : `./overlay-main-sample-1.component.html` ,
styleUrls : [`./overlay-main-sample-1.component.scss` ]
})
export class OverlaySampleMain1Component implements OnDestroy {
private _overlayId: string ;
constructor (@Inject (IgxOverlayService) public overlayService: IgxOverlayService ) {}
public showOverlay ( ) {
if (!this ._overlayId) {
this ._overlayId = this .overlayService.attach(MyDynamicCardComponent);
}
this .overlayService.show(this ._overlayId);
}
public ngOnDestroy(): void {
if (this ._overlayId) {
this .overlayService.detach(this ._overlayId);
delete this ._overlayId;
}
}
}
ts コピー <div class ="content" >
<button class ="igx-button--raised" #buttonElement igxButton (click )='showOverlay()' >
Show Card
</button >
</div >
html コピー .content {
width : 100% ;
height : 100% ;
}
button {
margin-top : 10% ;
margin-left : 45% ;
width : 160px ;
}
scss コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
はじめに
はじめに、IgxOverlayService
をインポートし、コンポーネントへの参照をコンポーネントのコンストラクターに注入
する必要があります。
import { Inject } from '@angular/core'
import { IgxOverlayService } from `igniteui-angular` ;
...
export class MyOverlayComponent {
constructor (
@Inject (IgxOverlayService) private overlayService: IgxOverlayService
) {}
}
...
typescript
コンテンツの表示
オーバーレイ サービスでオーバーレイ DOM にアタッチすると HTMLNode
または Angular コンポーネントを動的に表示できます。
Overlay サービスへの参照を追加した後、コンテンツを動的に表示/非表示できます。たとえば、Angular コンポーネントは attach
メソッドで渡せます。これは一意の ID を生成し、show
メソッドに渡してコンポーネントを表示します。Angular コンポーネントを表示する場合、attach
メソッドに 2 番目の必須パラメーター ViewContainerRef
を渡す必要があります。
import { MyDynamicComponent } from '../my-dynamic-component/my-dynamic-component.component' ;
@Component ({...})
export class MyOverlayComponent {
private _overlayId = '' ;
constructor (
@Inject (IgxOverlayService) private overlayService: IgxOverlayService,
private viewContainerRef: ViewContainerRef
) {}
public showInOverlay ( ) {
if (!this ._overlayId) {
this ._overlayId = this .overlayService.attach(MyDynamicComponent, this .viewContainerRef);
}
this .overlayService.show(this ._overlayId);
}
}
typescript
<div class ='content' >
...
<button (click )="showInOverlay()" > Show Overlay</button >
</div >
HTML
ページの既存の ElementRef
から IgxOverlayService
へ渡す場合は以下の手順に従ってください。
<div class ='content' >
<button (click )="showInOverlay()" > Show Overlay</button >
</div >
<div >
<img #exampleImage width ='200px' src ='../assets/example.png' title ='Click Me!' >
</div >
HTML
import { Inject, ViewChild } from '@angular/core'
@Component ({...})
export class MyOverlayComponent {
private _overlayId = '' ;
@ViewChild ('exampleImage' , {read : ElementRef})
private exampleImage: ElementRef;
public showInOverlay ( ) {
if (!this ._overlayId) {
this ._overlayId = this .overlayService.attach(this .exampleImage);
}
this .overlayService.show(this ._overlayId);
}
}
typescript
Overlay サービスの attach()
メソッドには 2 つのオーバーロードがあります。
attach(element, settings?)
attach(component, viewContainerRef, settings?)
オーバーロードの最初のパラメーターは必須でオーバーレイに表示されるコンテンツを表します。以下は、コンテンツを渡す場合の例です。
コンポーネント定義 - コンポーネントを最初の引数として渡す場合、オーバーレイ サービスがそのコンポーネントの新しいインスタンスを作成し、その ElementRef
を動的に オーバーレイ
DOM にアタッチします。このメソッドは、2 番目の必須パラメーター ViewContainerRef
に、作成されたコンポーネントのホスト ビューが挿入されるコンテナへの参照も受け入れます。
ElementRef
から既存の DOM 要素 (上記のサンプルを参照) - ページで既に描画されたビューはオーバーレイ サービスで渡して、オーバーレイ DOM で描画できます。
どちらの場合も、attach()
メソッドは次のようになります:
Angular から渡されるビューへの参照を取得します。
ビューを DOM からデタッチし、そこにアンカーを追加します。
提供されている OverlaySettings
を使用するか、デフォルトのオーバーレイにフォールバックして、ビューをオーバーレイに再アタッチします。
次に show(id)
を呼び出すと、開くアニメーションが再生され、添付されたコンテンツが表示されます。hide(id)
を呼び出すと、閉じるアニメーションが再生され、添付されているコンテンツが非表示になります。
最後に detach(id)
メソッドを呼び出すと、ビューが DOM 内の元の場所に再アタッチされます。コンポーネントが attach()
メソッドに提供された場合、detach(id)
を呼び出すと、作成されたインスタンスが破棄されます。
コンポーネントのアタッチ
閉じた後、ビューを DOM にある元の位置にアタッチします。以下のデモでは、IgxCard コンポーネントをオーバーレイ サービスの attach()
メソッドに渡し、IDを生成します。次に、提供された ID で show()
メソッドを呼び出し、カードをモーダル コンテナーで DOM にアタッチします。
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 {
IgxIconModule,
IgxOverlayService,
IgxCardModule
} from "igniteui-angular" ;
import { OverlaySampleMain1Component } from "./overlay-main-1/overlay-main-sample-1.component" ;
import { MyDynamicCardComponent } from "./overlay-dynamic-card/overlay-dynamic-card.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
OverlaySampleMain1Component,
MyDynamicCardComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxIconModule,
IgxCardModule
],
providers : [IgxOverlayService],
entryComponents : [MyDynamicCardComponent],
schemas : []
})
export class AppModule {}
ts コピー import { Component, Inject, OnDestroy } from '@angular/core' ;
import { IgxOverlayService } from 'igniteui-angular' ;
import { MyDynamicCardComponent} from '../overlay-dynamic-card/overlay-dynamic-card.component' ;
@Component ({
selector : 'app-overlay-sample' ,
templateUrl : `./overlay-main-sample-1.component.html` ,
styleUrls : [`./overlay-main-sample-1.component.scss` ]
})
export class OverlaySampleMain1Component implements OnDestroy {
private _overlayId: string ;
constructor (@Inject (IgxOverlayService) public overlayService: IgxOverlayService ) {}
public showOverlay ( ) {
if (!this ._overlayId) {
this ._overlayId = this .overlayService.attach(MyDynamicCardComponent);
}
this .overlayService.show(this ._overlayId);
}
public ngOnDestroy(): void {
if (this ._overlayId) {
this .overlayService.detach(this ._overlayId);
delete this ._overlayId;
}
}
}
ts コピー <div class ="content" >
<button class ="igx-button--raised" #buttonElement igxButton (click )='showOverlay()' >
Show Card
</button >
</div >
html コピー .content {
width : 100% ;
height : 100% ;
}
button {
margin-top : 10% ;
margin-left : 45% ;
width : 160px ;
}
scss コピー
オーバーレイ設定
attach()
メソッドは OverlaySettings
型のオブジェクトを受け取ります。このオブジェクトはコンテンツの表示方法を構成します。このオブジェクトが指定されていない場合、Overlay サービスは渡されたコンテンツを描画するためにデフォルト設定を使用します。
たとえば、コンテンツを要素に相対的に配置するには、オーバーレイの attach()
メソッドに別の target
と positioningStrategy
(ConnectedPositioningStrategy
など) を渡します。コンポーネントの表示方法を構成するには、最初に OverlaySettings
オブジェクトを作成します。
import { ConnectedPositioningStrategy } from 'igniteui-angular' ;
...
export class MyOverlayComponent {
@ViewChild (`myAnchorButton` )
private myAnchorButton: ElementRef;
private _overlayId = '' ;
public showInOverlay ( ) {
if (!this ._overlayId) {
this ._overlayId = this .overlayService.attach(MyDynamicComponent, this .viewContainerRef, {
target : this .myAnchorButton.nativeElement,
positionStrategy : new ConnectedPositioningStrategy()
});
}
this .overlayService.show(this ._overlayId);
}
}
typescript
<div class ='content' >
...
<button #myAnchorButton (click )="showInOverlay()" > Show Overlay</button >
</div >
HTML
ボタンをクリックすると、ボタンに相対的に配置される MyDynamicComponent
を表示します。
プリセット オーバーレイ設定
IgxOverlayService.createAbsolutePositionSettings()
および IgxOverlayService.createRelativePositionSettings()
メソッドにより、事前定義された設定セットに基づいて OverlaySettings
を容易に作成することができます。
IgxOverlayService.createAbsolutePositionSettings()
メソッドは、outlet
パラメーターが指定されている場合、GlobalPositionStrategy
または ContainerPositionStrategy
を使用して非モーダル OverlaySettings
を作成します。AbsolutePosition
列挙体は、Center
、Top
、または Bottom
から選択できる位置を定義します。デフォルトの位置は Center
です。
const globalOverlaySettings = IgxOverlayService.createAbsoluteOverlaySettings(AbsolutePosition.Top);
typescript
IgxOverlayService.createRelativePositionSettings()
メソッドは、AutoPositionStrategy
、ConnectedPositioningStrategy
または ElasticPositionStrategy
を使用して OverlaySettings
を作成します。ターゲット、位置およびストラテジを受け入れます。target
は、コンポーネントが表示するアタッチ ポイントまたは要素です。position
は RelativePosition
列挙体であり、次のオプションがあります: Above
、Below
、Before
、After
、Default
。Default
オプションは、要素をターゲットの下に配置し、左揃えにします。位置ストラテジは、RelativePositionStrategy
列挙体を介して設定できます。デフォルト値は Auto
です。
const targetElement = this .myAnchorButton.nativeElement;
const connectedOverlaySettings = IgxOverlayService.createRelativeOverlaySettings(
targetElement,
RelativePosition.Above,
RelativePositionStrategy.Connected);
typescript
デモ
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 {
IgxIconModule,
IgxOverlayService,
IgxCardModule,
IgxButtonGroupModule,
IgxButtonModule
} from "igniteui-angular" ;
import { OverlayPresetSettingsSampleComponent } from "./overlay-preset-settings/overlay-preset-settings-sample.component" ;
import { MyDynamicCardComponent } from "./overlay-dynamic-card/overlay-dynamic-card.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
OverlayPresetSettingsSampleComponent,
MyDynamicCardComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxIconModule,
IgxCardModule,
IgxButtonGroupModule,
IgxButtonModule
],
providers : [IgxOverlayService],
entryComponents : [MyDynamicCardComponent],
schemas : []
})
export class AppModule {}
ts コピー import {
Component,
ElementRef,
Inject,
OnDestroy,
OnInit,
ViewChild
} from '@angular/core' ;
import {
AbsolutePosition,
IgxOverlayService,
OverlaySettings,
RelativePosition,
RelativePositionStrategy,
IButtonGroupEventArgs
} from 'igniteui-angular' ;
import { MyDynamicCardComponent } from '../overlay-dynamic-card/overlay-dynamic-card.component' ;
@Component ({
selector : 'app-overlay-sample' ,
styleUrls : ['./overlay-preset-settings-sample.component.scss' ],
templateUrl : './overlay-preset-settings-sample.component.html' ,
providers : [IgxOverlayService]
})
export class OverlayPresetSettingsSampleComponent implements OnInit , OnDestroy {
@ViewChild ('anchor' , { static : true })
public anchor: ElementRef;
@ViewChild ('outlet' , { static : true })
public outlet: ElementRef;
public positionStrategies = ['relative' , 'absolute' ];
public positionStrategy = this .positionStrategies[0 ];
public absStrategies = ['container' , 'global' ];
public absPositions = [
AbsolutePosition.Center,
AbsolutePosition.Top,
AbsolutePosition.Bottom
];
public relStrategies = [
RelativePositionStrategy.Auto,
RelativePositionStrategy.Connected,
RelativePositionStrategy.Elastic
];
public relPositions = [
RelativePosition.Default,
RelativePosition.Above,
RelativePosition.Below,
RelativePosition.Before,
RelativePosition.After
];
public absPositionStrategy = this .absStrategies[0 ];
public absPosition = AbsolutePosition.Center;
public relPositionStrategy = RelativePositionStrategy.Auto;
public relPosition = RelativePosition.Default;
private _overlayId: string ;
private _overlaySettings: OverlaySettings;
constructor (@Inject (IgxOverlayService) public overlayService: IgxOverlayService ) { }
public ngOnInit(): void {
this .setRelativeOverlaySettings();
}
public ngOnDestroy(): void {
if (this ._overlayId) {
this .overlayService.detach(this ._overlayId);
delete this ._overlayId;
}
}
public showOverlay ( ) {
if (this ._overlayId) {
this .overlayService.detach(this ._overlayId);
delete this ._overlayId;
}
this ._overlayId = this .overlayService.attach(
MyDynamicCardComponent,
this ._overlaySettings
);
this .overlayService.show(this ._overlayId);
}
public selectPositionStrategy (event: IButtonGroupEventArgs ) {
this .positionStrategy = this .positionStrategies[event.index];
}
public selectAbsStrategy (event: IButtonGroupEventArgs ) {
this .absPositionStrategy = this .absStrategies[event.index];
this .setAbsoluteOverlaySettings(this .absPositionStrategy);
}
public selectRelStrategy (event: IButtonGroupEventArgs ) {
this .relPositionStrategy = this .relStrategies[event.index];
this .setRelativeOverlaySettings();
}
public selectAbsPosition (event: IButtonGroupEventArgs ) {
this .absPosition = this .absPositions[event.index];
this .setAbsoluteOverlaySettings(this .absPositionStrategy);
}
public selectRelPosition (event: IButtonGroupEventArgs ) {
this .relPosition = this .relPositions[event.index];
this .setRelativeOverlaySettings();
}
private setAbsoluteOverlaySettings (strategy: string ) {
switch (strategy) {
case 'container' :
this ._overlaySettings = IgxOverlayService.createAbsoluteOverlaySettings(
this .absPosition,
this .outlet
);
break ;
case 'global' :
default :
this ._overlaySettings = IgxOverlayService.createAbsoluteOverlaySettings(
this .absPosition
);
break ;
}
}
private setRelativeOverlaySettings ( ) {
this ._overlaySettings = IgxOverlayService.createRelativeOverlaySettings(
this .anchor.nativeElement,
this .relPosition,
this .relPositionStrategy
);
}
}
ts コピー <ng-template #header let-title ="title" >
<header class ="filter-group__header" >
<h1 class ="ig-typography__overline" > {{ title }}</h1 >
</header >
</ng-template >
<article
#outlet
class ="outlet-group"
[class.outlet-group--active ]="
positionStrategy === 'absolute' && absPositionStrategy === 'container'
"
>
<section
#anchor
class ="outlet-group__anchor"
[class.outlet-group__anchor--active ]="positionStrategy === 'relative'"
>
<igx-icon > anchor</igx-icon >
</section >
<header >
<h1 class ="ig-typography__h5 outlet-group__title" >
Outlet Container
</h1 >
<h2 class ="ig-typography__body-1 outlet-group__subtitle" >
The card will be positioned relative to the container or the anchor
based on the selected <em > <b > type and strategy</b > </em
>.
</h2 >
</header >
</article >
<article class ="filter-group" >
<ng-container
*ngTemplateOutlet ="header; context: { title: 'Type' }"
> </ng-container >
<igx-buttongroup (selected )="selectPositionStrategy($event)" >
<button
igxButton
*ngFor ="let item of positionStrategies; let i = index"
[selected ]="positionStrategy === positionStrategies[i]"
>
{{ item }}
</button >
</igx-buttongroup >
</article >
<article class ="filter-group" *ngIf ="positionStrategy === 'absolute'" >
<ng-container
*ngTemplateOutlet ="header; context: { title: 'Position' }"
> </ng-container >
<igx-buttongroup (selected )="selectAbsPosition($event)" >
<button
igxButton
*ngFor ="let item of absPositions; let i = index"
[selected ]="absPosition === absPositions[i]"
>
{{ item }}
</button >
</igx-buttongroup >
</article >
<article class ="fitler-group" *ngIf ="positionStrategy === 'absolute'" >
<ng-container
*ngTemplateOutlet ="header; context: { title: 'Strategy' }"
> </ng-container >
<igx-buttongroup (selected )="selectAbsStrategy($event)" >
<button
igxButton
*ngFor ="let item of absStrategies; let i = index"
[selected ]="absPositionStrategy === absStrategies[i]"
>
{{ item }}
</button >
</igx-buttongroup >
</article >
<article class ="filter-group" *ngIf ="positionStrategy === 'relative'" >
<ng-container
*ngTemplateOutlet ="header; context: { title: 'Position' }"
> </ng-container >
<igx-buttongroup (selected )="selectRelPosition($event)" >
<button
igxButton
*ngFor ="let item of relPositions; let i = index"
[selected ]="relPosition === relPositions[i]"
>
{{ item }}
</button >
</igx-buttongroup >
</article >
<article class ="filter-group" *ngIf ="positionStrategy === 'relative'" >
<ng-container
*ngTemplateOutlet ="header; context: { title: 'Strategy' }"
> </ng-container >
<igx-buttongroup (selected )="selectRelStrategy($event)" >
<button
igxButton
*ngFor ="let item of relStrategies; let i = index"
[selected ]="relPositionStrategy === relStrategies[i]"
>
{{ item }}
</button >
</igx-buttongroup >
</article >
<button #buttonElement igxButton ="raised" (click )="showOverlay()" >
Apply Settings
</button >
html コピー @use '../../variables' as *;
:host {
position : relative;
display : block;
padding : rem(12px );
}
@include b(outlet-group) {
position : relative;
display : flex;
flex-direction : column;
align-items : center;
justify-content : center;
background : color($color : 'gray' , $variant : 100 );
border : 2px dashed color($color : 'gray' , $variant : 200 );
border-radius : rem(8px );
padding : rem(12px );
height : 376px ;
@include e(anchor) {
display : flex;
justify-content : center;
align-items : center;
width : rem(80px );
height : rem(80px );
margin-bottom : rem(24px );
border : 2px dashed color($color : 'gray' , $variant : 300 );
border-radius : rem(8px );
color : color($color : 'gray' , $variant : 800 );
igx-icon {
font-size : 64px ;
width : 64px ;
height : 64px ;
}
}
@include e(anchor, active) {
border-color : color($color : 'primary' );
}
@include e(title) {
text-align : center;
margin : 0 ;
color : color($color : 'gray' , $variant : 800 );
}
@include e(subtitle) {
text-align : center;
margin : 0 ;
color : color($color : 'gray' , $variant : 600 );
}
@include m(active) {
border-color : color($color : 'primary' );
}
}
@include b(filter-group) {
@include e(header) {
h1 {
font-size : rem(12px );
margin-bottom : rem(8px );
}
}
}
[igxButton="raised" ] {
margin : rem(24px ) 0 ;
}
scss コピー
オーバーレイの非表示
hide(id)
は、オーバーレイ コンテンツを非表示にします。すべてのオーバーレイ サービスで描画される要素がサービスによって割り当てられた一意の ID があります。attach()
メソッドは、描画されたコンテンツの識別子を返します。コンテンツを非表示にするには、この ID をオーバーレイの hide(id)
メソッドに渡す必要があります。すべてのオーバーレイを非表示にするには、hideAll()
メソッドを呼び出すことができます。
描画されたコンテンツが不要になったら、detach(id)
メソッドを呼び出す必要があります。このメソッドは、オーバーレイからコンテンツを削除し、該当する場合は、DOM 内の元の場所にコンテンツを再アタッチします。detach(id)
メソッドは、attach()
メソッドから生成された ID も必須パラメーターとして受け入れます。すべてのオーバーレイを削除するには、detachAll()
メソッドを呼び出すことができます。
以前に定義されたオーバーレイ メソッドをオーバーレイ要素を表示して非表示するために変更できます。
import { ConnectedPositioningStrategy } from 'igniteui-angular' ;
@Component ({...})
export class MyOverlayComponent implements OnDestroy {
private _overlayId = '' ;
private _overlayShown = false ;
@ViewChild (`myAnchorButton` )
private myAnchorButton: ElementRef;
public toggleOverlay ( ) {
if (!this ._overlayShown) {
if (!this ._overlayId) {
this ._overlayId = this .overlayService.attach(MyDynamicComponent, this .viewContainerRef, {
target : this .myAnchorButton.nativeElement,
positionStrategy : new ConnectedPositioningStrategy({
closeOnOutsideClick : false ,
modal : false
})
});
}
this .overlayService.show(this ._overlayId);
} else {
this .overlayService.hide(this ._overlayId);
}
this ._overlayShown = !this ._overlayShown;
}
public ngOnDestroy(): void {
if (this ._overlayId) {
this .overlayService.detach(this ._overlayId);
delete this ._overlayId;
}
}
}
typescript
<div class ='content' >
...
<button #myAnchorButton (click )="toggleOverlay()" > Toggle Overlay</button >
</div >
HTML
アタッチ設定
attach()
メソッドの overlaySettings
パラメーターを使用してコンテンツの表示方法を変更できます。たとえば、コンテンツの配置、スクロールの動作、およびコンテナーがモーダルかどうかを設定できます。
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 {
IgxIconModule,
IgxOverlayService,
IgxSwitchModule,
IgxCardModule,
IgxButtonDirective,
IgxDividerModule,
IgxButtonModule
} from "igniteui-angular" ;
import { OverlaySampleMain2Component } from "./interactions/overlay/overlay-main-2/overlay-main-sample-2.component" ;
import { CardSample1Component } from "./layouts/card/card-sample-1/card-sample-1.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
OverlaySampleMain2Component,
CardSample1Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxIconModule,
IgxCardModule,
IgxDividerModule,
IgxButtonModule
],
providers : [IgxOverlayService],
entryComponents : [CardSample1Component],
schemas : []
})
export class AppModule {}
ts コピー import { Component, ElementRef, Inject, OnDestroy, ViewChild } from '@angular/core' ;
import { ConnectedPositioningStrategy, IgxOverlayService } from 'igniteui-angular' ;
import { CardSample1Component } from '../../../layouts/card/card-sample-1/card-sample-1.component' ;
@Component ({
selector : 'app-overlay-sample' ,
templateUrl : `./overlay-main-sample-2.component.html` ,
styleUrls : [`./overlay-main-sample-2.component.scss` ]
})
export class OverlaySampleMain2Component implements OnDestroy {
@ViewChild ('buttonElement' , { static : true })
private buttonElement: ElementRef;
private _overlayId: string ;
private _cardHidden = true ;
constructor (
@Inject (IgxOverlayService) public overlayService: IgxOverlayService ) {}
public toggleOverlay ( ) {
if (this ._cardHidden) {
if (!this ._overlayId) {
const positionStrategy = new ConnectedPositioningStrategy();
this ._overlayId = this .overlayService.attach(CardSample1Component, {
target : this .buttonElement.nativeElement,
positionStrategy,
modal : false ,
closeOnOutsideClick : false
});
}
this .overlayService.show(this ._overlayId);
} else {
this .overlayService.hide(this ._overlayId);
}
this ._cardHidden = !this ._cardHidden;
}
public ngOnDestroy(): void {
if (this ._overlayId) {
this .overlayService.detach(this ._overlayId);
delete this ._overlayId;
}
}
}
ts コピー <div class ="content" >
<button class ="igx-button--raised" #buttonElement igxButton (click )='toggleOverlay()' >
Toggle Card
</button >
</div >
html コピー .content {
width : 100% ;
height : 100% ;
}
button {
margin-top : 10% ;
margin-left : 45% ;
width : 160px ;
}
scss コピー
overlaySettings
が指定されていない場合、切り替えた要素はデフォルト表示設定を使用します。
defaultOverlaySettings = {
positionStrategy : new GlobalPositionStrategy(),
scrollStrategy : new NoOpScrollStrategy(),
modal : true ,
closeOnOutsideClick : true ,
closeOnEscape : false
};
typescript
igxToggle との統合
IgxToggleDirective
は IgxOverlayService
と完全に統合されます。コンテンツの切り替えで Toggle ディレクティブの toggle()
メソッドにカスタム オーバーレイ設定を渡すことができます。
構成設定をトグルのメソッドに渡す方法は以下の例で紹介されます。
<div >
<button igxToggle (click )="callToggle()" > Click me!</button >
<div [style.visibility ]="collapsed ? 'hidden ' : 'visible'" >
This content is toggle-able!
</div >
</div >
html
@Component ({
selector : `example-component` ,
template : `example.component.html`
})
export class ExampleComponent {
@ViewChild (IgxToggleDirective)
private toggleDirective: IgxToggleDirective;
public get collapsed (): boolean {
return this .toggleDirective.collapsed;
}
public callToggle(): void {
const overlaySettings: OverlaySettings = {
positionStrategy : new AutoPositionStrategy(),
scrollStrategy : new BlockScrollStrategy(),
modal : true ,
closeOnOutsideClick : false
}
this .toggleDirective.toggle(overlaySettings)
}
}
typescript
仮定と制限
アウトレットにオーバーレイを表示する際にアウトレットが CSS で変換、視点、またはフィルターが設定された要素の子である場合、モーダル オーバーレイが表示されません。これは、上記のいずれかの CSS プロパティが設定された際にブラウザーが新しく含まれるブロックを作成してこちら のようにオーバーレイがこのブロックに制限されるためです。
API リファレンス
その他のリソース