NgCordova + Vibrate


#1

Hello !

I’m trying to make the vibration work, but I don’t know why it doesn’t.
I always have : Uncaught TypeError: Cannot read property 'vibrate' of undefined

It’s on my phone, not in browser (I don’t want to shake my window :smile:)

I’ve included ng-cordova.js in my head of index.html

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/ng-cordova.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

in my app.js

angular.module('xxxx', ['ngCordova', 'ionic','xxx.controllers', 'xxx.services', 'xxx.filters', 'xxx.directives'])

and my AuthController.js

angular.module('xxx.controllers')
	.controller('AuthController.index', ["$scope", "$ionicPlatform", "$state", "$ionicSideMenuDelegate", "$window", "$cordovaVibration",
		function($scope, $ionicPlatform, $state, $ionicSideMenuDelegate, $window, $cordovaVibration) {
			// Vérification que la personne est loguée
			if ($window.sessionStorage['token']) {
				$state.go('app.home');
			}
			$ionicPlatform.ready(function() {
				console.log("i'm ready");
				$cordovaVibration.vibrate(10000)
			})
		}
	])

What I really don’t understand is why it works with the toast, but not the vibrate… :confused:

Hope you can help me

Kai23


#2

Have you included the actual cordova plugin?


#3

Hi,

It was indeed the problem. My real error was with the Cordova App Preference plugin, which doesnt work at all for me.