DevicePosture
Reactive wrapper around the Device Posture API. Track device posture state for foldable devices with Angular signals.
Usage
import { Component } from '@angular/core';
import { devicePosture } from '@signality/core';
@Component({
template: `
<p>Posture: {{ posture.type() }}</p>
`,
})
export class PostureDemo {
readonly posture = devicePosture();
}Use InjectionToken for Singleton
For global state tracking like devicePosture, consider using the provided DEVICE_POSTURE token instead of calling the function directly. This ensures a singleton instance shared across your entire application, reducing memory usage and event listener overhead:
import { inject } from '@angular/core';
import { DEVICE_POSTURE } from '@signality/core';
const posture = devicePosture();
const posture = inject(DEVICE_POSTURE); Learn more about Token-based utilities.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | WithInjector | Optional configuration (see Options below) |
Options
The WithInjector interface provides:
| Option | Type | Description |
|---|---|---|
injector | Injector | Optional injector for DI context |
Return Value
The devicePosture() function returns a DevicePostureRef object:
| Property | Type | Description |
|---|---|---|
isSupported | Signal<boolean> | Whether Device Posture API is supported |
type | Signal<DevicePostureType> | Current device posture ('continuous' or 'folded') |
Examples
Adaptive layout for foldable devices
import { Component, computed } from '@angular/core';
import { devicePosture } from '@signality/core';
@Component({
template: `
<div [class]="posture.type()">
<div class="panel">Content</div>
</div>
`,
})
export class AdaptiveLayout {
readonly posture = devicePosture();
}Browser Compatibility
The Device Posture API has limited browser support. Always check isSupported() before relying on posture data (see Browser API support detection):
@if (posture.isSupported()) {
<p>Posture: {{ posture.type() }}</p>
} @else {
<p>Device Posture API is not supported in this browser</p>
}For detailed browser support information, see Can I use: Device Posture API.
SSR Compatibility
On the server, signals initialize with safe defaults:
isSupported→falsetype→'continuous'
Type Definitions
type DevicePostureType = 'continuous' | 'folded';
interface DevicePostureRef {
readonly isSupported: Signal<boolean>;
readonly type: Signal<DevicePostureType>;
}
function devicePosture(options?: WithInjector): DevicePostureRef;
const DEVICE_POSTURE: InjectionToken<DevicePostureRef>;Related
- WindowSize — Window dimensions tracking
- ScreenOrientation — Screen orientation tracking