Overview
TheDialogService is a shared Angular service that manages Material Design dialogs for displaying media item details and trailers. It uses lazy loading to dynamically import dialog components on demand, improving initial load performance.
Import
Dependencies
The service depends on:MatDialogfrom@angular/material/dialogOmdbServicefor fetching detailed media informationToastrServicefromngx-toastrfor error notifications
Methods
openMediaItem
Opens a Material dialog displaying detailed information about a media item (movie, series, or game). The dialog is lazily loaded and its size adapts to the window dimensions.The current window width in pixels, used to calculate optimal dialog dimensions
The media item to display. Must include at minimum the
imdbID propertyIndicates whether the dialog was opened from the favorites page (enables edit/delete actions)
An Observable that completes when the dialog operation finishes. Errors are handled internally with toast notifications.
- Mobile (<600px): 90% height, 80% width
- Tablet (600-800px): 85% height, 70% width
- Desktop (>800px): 85% height, 85% width
navbar.component.ts
Lazy Load Component
Dynamically imports
MediaItemDialogComponent using dynamic import() for code splittingopenTrailerDialog
Opens a Material dialog for playing a video trailer from a URL (typically YouTube). The component is lazily loaded on demand.The URL of the video to play. Typically a YouTube URL that will be sanitized and embedded in an iframe
- Width: 80% of viewport width (max 1200px)
- Height: 70% of viewport height (max 800px)
- Auto-focus disabled for better UX
- User can close by clicking outside or pressing ESC
movie-dialog.component.ts
Implementation Details
Lazy Loading Pattern
Both dialog methods use dynamicimport() to lazy load their components:
- Reduces initial bundle size
- Loads dialog code only when needed
- Improves application startup time
RxJS Integration
openMediaItem() returns an Observable that chains:
- API call to fetch media details
- Component import
- Dialog opening
Related
MediaItem Model
The data model passed to dialog methods
OmdbService
Service that fetches detailed media information
Movie Dialog Component
The lazily-loaded dialog component for media details
Trailer Dialog Component
The lazily-loaded dialog component for video playback
Usage in Components
DialogService is typically injected into components that need to display media details:The service handles all error cases internally with toast notifications, so components don’t need to implement additional error handling.