Ionic ng-cordova vibrating plugin not working

I am new to ionic and cordova, this vibrating plugin is not working. Could you please point out the error?

This is index.html:

<body ng-app="starter">
        <ion-header-bar class="bar-stable">
            <h1 class="title">Ionic Blank Starter</h1>
        <ion-content ng-controller="myCtrl">
            <button ng-click="toggle()">Toggle</button>


This is the app.js folder in js:

var ionicApp = angular.module('starter', ['ionic', 'ngCordova'])

ionicApp.controller("myCtrl", function($scope, $cordovaVibration)) {

    $scope.toggle = function() {
        $ionicPlatform.ready(function() {
            $cordovaVibration.vibrate(100).then(function() {
                console.log("Phone vibrating");




.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
        if (window.StatusBar) {


I added a widget plugin ng-cordova



source to share

2 answers

I had the same problems, mine was solved by adding a Cordova plugin, it looks like you took care of that: here are my differences from your project:

I used this version of the Ready platform

    $scope.toggle = function() {
      document.addEventListener( "deviceready", function() {
           $cordovaVibration.vibrate( 2000 ); }, false );


My ionic App definition I first installed ngCordova. Although this may not be a problem

var ionicApp = angular.module('starter', ['ngCordova','ionic' ])


Which solves the problem for me, need to install the plugin correctly: Try:

 cordova plugin add cordova-plugin-vibration


instead of the official site, which reads:

cordova plugin add org.apache.cordova.vibration


I added permission to /platforms/android/AndroidManifest.xm. Although this is apparently not necessary, because I believe ion collecting or ion triggering detects that you are using vibration and adding it for yourself.

  <uses-permission android:name="android.permission.VIBRATE" />




When testing on a device, make sure the device is turned off. Many (most) devices will drown out vibration as well as sound. If you are debugging your browser, you should see Vibration for Xms. in the console, where "X" is the number of milliseconds you fed to the vibration function. This indicates that the plugin is working (obviously, you cannot vibrate your computer). But, again, when testing on a device, make sure it's not disabled.



All Articles