@angular/cdk/overlay package provides a flexible system for displaying floating panels on top of your app’s content.
Installation
Basic Usage
Creating an Overlay
Position Strategies
Global Positioning
Connected Positioning
Scroll Strategies
- close() - Close overlay on scroll
- noop() - Do nothing
- block() - Block scrolling
- reposition() - Reposition overlay
Advanced Examples
Dropdown Menu
Tooltip
API Reference
Overlay Service
| Method | Returns | Description |
|---|---|---|
create(config?) | OverlayRef | Create an overlay |
position() | OverlayPositionBuilder | Get position builder |
scrollStrategies | Object | Access scroll strategies |
OverlayConfig
| Property | Type | Description |
|---|---|---|
hasBackdrop | boolean | Whether to show backdrop |
backdropClass | string | string[] | CSS classes for backdrop |
panelClass | string | string[] | CSS classes for pane |
positionStrategy | PositionStrategy | How to position overlay |
scrollStrategy | ScrollStrategy | Handle scroll behavior |
width | number | string | Overlay width |
height | number | string | Overlay height |
minWidth | number | string | Minimum width |
minHeight | number | string | Minimum height |
maxWidth | number | string | Maximum width |
maxHeight | number | string | Maximum height |
OverlayRef
| Method | Returns | Description |
|---|---|---|
attach(portal) | ComponentRef | EmbeddedViewRef | Attach content |
detach() | void | Detach content |
dispose() | void | Destroy overlay |
hasAttached() | boolean | Check if attached |
backdropClick() | Observable<MouseEvent> | Backdrop click events |
keydownEvents() | Observable<KeyboardEvent> | Keyboard events |
outsidePointerEvents() | Observable<MouseEvent> | Outside click events |
Position Strategies
FlexibleConnectedPositionStrategy
GlobalPositionStrategy
Best Practices
- Dispose overlays - Always clean up when done
- Use appropriate scroll strategy - Match UX expectations
- Handle keyboard - Close on Escape key
- Accessibility - Manage focus and ARIA
- Portal reuse - Detach instead of dispose when possible