import { Component } from '@angular/core';
import { WrCompare } from 'ngwr/compare';
@Component({ imports: [WrCompare] })
export class MyComponent {}Compare
A before and after view split by a draggable divider.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Image compare
Mark the layers wrCompareBefore and wrCompareAfter; drag the divider or use the arrow keys (Shift moves 10 points).
<wr-compare [(position)]="pos">
<img wrCompareBefore src="before.jpg" alt="" />
<img wrCompareAfter src="after.jpg" alt="" />
</wr-compare>Vertical split
orientation="vertical" splits top from bottom.
<wr-compare orientation="vertical">
<img wrCompareBefore src="before.jpg" alt="" />
<img wrCompareAfter src="after.jpg" alt="" />
</wr-compare>Arbitrary content
Any content works; without an image to size it, set a height on <wr-compare>.
<wr-compare style="height: 12rem">
<div wrCompareBefore>…before content…</div>
<div wrCompareAfter>…after content…</div>
</wr-compare>API
| Name | Description | Type | Default |
|---|---|---|---|
position | Divider position as a percentage (0–100). Two-way bindable. | number | 50 |
ariaLabel | Accessible name of the divider. Falls back to compare.label. | string | null | null |
orientation | Divider direction: - 'horizontal' — divider line is vertical, drags left/right. - 'vertical' — divider line is horizontal, drags up/down. | 'horizontal' | 'vertical' | 'horizontal' |
showHandle | Show the round drag handle on the divider. | boolean | true |
disabled | Disable interaction (divider stays put). | boolean | false |
minPosition | Lowest position the divider may reach, in percent. | number | 0 |
maxPosition | Highest position the divider may reach, in percent. | number | 100 |
Content slots
| Name | Description | Type | Default |
|---|---|---|---|
[wrCompareBefore] / [wrCompareAfter] | Attributes marking the two pieces of projected content. | attr | — |
