Class MainAspectComponent

MainAspectComponent dynamically adjusts its aspect ratio based on window size, providing an adaptable container for content. It listens for window resize and orientation changes to update its layout, making it suitable for responsive applications.

app-main-aspect-component

true

CommonModule

<div [ngStyle]="aspectStyles" [style.backgroundColor]="backgroundColor" class="aspect-container">
<ng-content></ng-content>
</div>
  • .aspect-container: Styles for overflow handling.
  • backgroundColor (string): The background color of the aspect container.
  • showControls (boolean): Toggles control display, adjusting the container height. Default is true.
  • containerWidthFraction (number): Fraction of window width for container width. Default is 1.
  • containerHeightFraction (number): Fraction of window height for container height. Default is 1.
  • defaultFraction (number): Height adjustment factor when controls are shown. Default is 0.94.
  • updateIsWideScreen (function): Callback to set wide screen status.
  • updateIsMediumScreen (function): Callback to set medium screen status.
  • updateIsSmallScreen (function): Callback to set small screen status.
  • ngOnInit(): Initializes component and sets up resize and orientation listeners.
  • ngOnChanges(changes: SimpleChanges): Updates layout when relevant inputs change.
  • ngOnDestroy(): Removes event listeners to prevent memory leaks.
  • updateAspectStyles(): Calculates and applies styles based on current window dimensions and component inputs.
<app-main-aspect-component
[backgroundColor]="'lightblue'"
[showControls]="true"
[containerWidthFraction]="0.9"
[containerHeightFraction]="0.8"
[defaultFraction]="0.95"
[updateIsWideScreen]="onWideScreenUpdate"
[updateIsMediumScreen]="onMediumScreenUpdate"
[updateIsSmallScreen]="onSmallScreenUpdate"
></app-main-aspect-component>

Implements

  • OnInit
  • OnDestroy
  • OnChanges

Constructors

Methods

Properties

backgroundColor: string = ''
showControls: boolean = true
containerWidthFraction: number = 1
containerHeightFraction: number = 1
defaultFraction: number = 0.94
updateIsWideScreen: ((isWideScreen: boolean) => void)
updateIsMediumScreen: ((isMediumScreen: boolean) => void)
updateIsSmallScreen: ((isSmallScreen: boolean) => void)
aspectStyles: {
    [key: string]: any;
} = {}