# ngx-vibration

> Angular directive for the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API) ## Setup

Latest version **1.2.0** (published 2023-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-vibration
pnpm add ngx-vibration
yarn add ngx-vibration
bun add ngx-vibration
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2023-12-03 |
| First published | 2019-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 36.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | spacycoder |
| Maintainers | spacycoder, simonjrnt |

## Links

- npm: https://www.npmjs.com/package/ngx-vibration
- Repository: https://github.com/spacycoder/ngx-vibration
- Homepage: https://github.com/spacycoder/ngx-vibration#readme
- Issues: https://github.com/spacycoder/ngx-vibration/issues
- npm.io page: https://npm.io/package/ngx-vibration

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.0.0

## Recent versions

- 1.2.0 (latest) — 2023-12-03
- 1.1.2 — 2022-02-02
- 1.1.1 — 2020-12-18
- 1.1.0 — 2020-11-13
- 1.0.0 — 2020-07-19
- 0.0.5 — 2019-08-16
- 0.0.4 — 2019-08-15
- 0.0.3 — 2019-08-15
- 0.0.2 — 2019-08-14
- 0.0.1 — 2019-08-14

## README

# NgxVibration
Angular directive for the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API)  
## Setup       

* Install with npm:
```bash
npm i ngx-vibration
```

* Import `NgxVibrationModule` in your App Module.
```typescript
import { NgxVibrationModule } from 'ngx-vibration';

@NgModule({
  imports: [..., NgxVibrationModule],
  ...
})
export class AppModule {}
```

## Usage

### Vibration Directive
The vibration directive causes the device to vibrate when the directive has been tapped by the user.

Add the ngxVibration directive to an HTML element. The directive takes a vibration pattern as input. The values of the array describes alternating periods of time in which the device is vibrating and not vibrating. 
```html
<button [ngxVibration]="[200, 100, 200]">VIBRATE</button>
```
```html
<button [ngxVibration]="500">VIBRATE</button>
```
Or with the [global config](#global-configuration) _defaultPattern_ set: 
```html
<button ngxVibration>VIBRATE</button>
```

### Vibration Service

```typescript
export class AppComponent implements OnInit {
  hasVibrationSupport = false;

  constructor(private vibrationService: NgxVibrationService) {}

  ngOnInit() {
    this.hasVibrationSupport = this.vibrationService.hasVibrationSupport();
  }

  vibrate() {
    this.vibrationService.vibrate([200, 100, 200]);
  }

  cancelVibration() {
    this.vibrationService.cancelVibration();
  }
}
```

### Global configuration

You can provide a default configuration object when importing the module using the `forRoot()` method.

``` typescript
NgxVibrationModule.forRoot({
  defaultPattern: [100, 0, 100]
})
```

| Property       | Type       | Description                                                  |
| -------------- | ---------- | ------------------------------------------------------------ |
| defaultPattern | `number[]` | The pattern to use by default when no other is specified on the directives |

---
_Source: https://npm.io/package/ngx-vibration · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
