Vibration Plugin with
Ionic Framework
ionic start ionic_project_vib blank //create ionic project
cd ionic_project_vib // go to project folder we created before
cordova plugin add cordova-plugin-vibration // add vibration
plugin
After all download ngCordova files : https://github.com/driftyco/ng-cordova/archive/master.zip
Get the ng-cordova.min.js file from inside of it then copy
under”www/js “
And cop and paste this url to our index.html
<script
type="text/javascript" src="js/ng-cordova.min.js"
></script>
We are ready to use cordova library in our ionic project .
Let’s add an button to activate vibration on our device
<button
class="button button-positive" ng-click="vibrate()"
>Vibrate</button>
So we had a button but it is not functional for cordova
.Let’s add ngCordova module
To our app.js file as a dependency
angular.module('starter',
['ionic','ngCordova'])
create vibrationCtrl and add vibrate function
.controller(vibrationCtrl,function($scope,$ionicPlatform,$cordovaVibration){
$scope.vibrate=function(){
$cordovaVibration.vibrate(100);
}
});
After this step you are able to use vibrationCtrl in html
side
<body ng-app="starter" ng-controller=" vibrationCtrl ">
Last step is
adding platfrom android/ios and build it or just run/emulate
ionic platform add android
ionic build android
Hiç yorum yok:
Yorum Gönder