1.2.0 • Published 5 months ago

ngx-vibration v1.2.0

Weekly downloads
27
License
MIT
Repository
github
Last release
5 months ago

NgxVibration

Angular directive for the Vibration API

Setup

  • Install with npm:
npm i ngx-vibration
  • Import NgxVibrationModule in your App Module.
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.

<button [ngxVibration]="[200, 100, 200]">VIBRATE</button>
<button [ngxVibration]="500">VIBRATE</button>

Or with the global config defaultPattern set:

<button ngxVibration>VIBRATE</button>

Vibration Service

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.

NgxVibrationModule.forRoot({
  defaultPattern: [100, 0, 100]
})
PropertyTypeDescription
defaultPatternnumber[]The pattern to use by default when no other is specified on the directives
1.2.0

5 months ago

1.1.2

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago