angularjs - ionic ng-cordova vibrate plugin not working -
i new ionic , cordova vibrate plugin not working. can please point out error?
this index.html:
<body ng-app="starter"> <ion-pane> <ion-header-bar class="bar-stable"> <h1 class="title">ionic blank starter</h1> </ion-header-bar> <ion-content ng-controller="myctrl"> <button ng-click="toggle()">toggle</button> </ion-content> </ion-pane> </body> this app.js in js folder:
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 accessory bar default (remove show accessory bar above keyboard // form inputs) if (window.cordova && window.cordova.plugins.keyboard) { cordova.plugins.keyboard.hidekeyboardaccessorybar(true); } if (window.statusbar) { statusbar.styledefault(); } }); }) i have added ng-cordova vibrate plugin.
i had same problems, mine solved adding cordova plugin, seems alredy took care of that: here differences project:
i used version of platform ready
$scope.toggle = function() { document.addeventlistener( "deviceready", function() { $cordovavibration.vibrate( 2000 ); }, false ); }; my ionic app definition placed ngcordova hookup first. although may not issue
var ionicapp = angular.module('starter', ['ngcordova','ionic' ]) what solves issue me installing plugin correctly: try:
cordova plugin add cordova-plugin-vibration instead of official site says:
cordova plugin add org.apache.cordova.vibration i added permission /platforms/android/androidmanifest.xm. although seems not necessary because believe ionic build or ionic run discover using vibration , add yourself
<uses-permission android:name="android.permission.vibrate" />
Comments
Post a Comment