@ngx-extensions/screenfull
Version:
Wrapper module for screenfull
82 lines (62 loc) • 2.17 kB
Markdown
# -extensions/screenfull
A simple wrapper around [screenfull.js](https://github.com/sindresorhus/screenfull.js) for Angular.
## Installation
```bash
npm install -extensions/screenfull
```
## Setup
Import `NgxScreenfullModule` into your module
```typescript
import { NgxScreenfullModule } from '@ngx-extensions/screenfull';
export class AppModule {}
```
## Usage
The most basic use case is to toggle the fullscreen mode through an element´s click event:
```html
<button ngxToggleFullscreen>Toggle fullscreen</button>
```
_Note: the host element of `ngxToggleFullscreen` does not necessarily have to be a `<button>`_
The state of the fullscreen mode can be tracked through the `ScreenfullService`
```typescript
import { ScreenfullService } from '@ngx-extensions/screenfull';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
export class DemoComponent {
readonly mode$: Observable<string>;
constructor(public readonly screenfullService: ScreenfullService) {
this.mode$ = this.screenfullService.fullScreenActive$.pipe(
map(active => (active ? 'active' : 'inactive'))
);
}
}
```
To interact with the fullscreen API, use the `ScreenfullService`:
```typescript
import { ScreenfullService } from '@ngx-extensions/screenfull';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
export class DemoComponent {
readonly mode$: Observable<string>;
constructor(public readonly screenfullService: ScreenfullService) {
this.mode$ = this.screenfullService.fullScreenActive$.pipe(
map(active => (active ? 'active' : 'inactive'))
);
}
}
```