I want to use Cordova Email Plugin in ionic application.
I can access plugin in $ionicPlatform function but when I moved my code to my controller in a function for handle ng-click it is not work.
Know my question is how to access cordova plugin objects from controller??
This is my code that I use in app.js and worked:
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
cordova.plugins.email.isAvailable(
function (isAvailable) {
alert('Service is available');
}
);
// 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) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
This is same code in controller.js that not worked (I set my controller in my route):
.controller('ApplicationController', function($scope) {
$scope.sendMail = function () {
cordova.plugins.email.isAvailable(
function (isAvailable) {
alert('Service is not available');
}
);
}
})
and this is my click call:
<a ng-click="sendMail()">
<i class="icon ion-android-forums"></i>
send mail
</a>
This is code works well in $ionicPlatform but don't work in seperate controller file.
You should use an Angular.js wrapper for this.
Check out ngCordova.
Try using window.cordova
instead of cordova
when referring to the plugin outside of $ionicPlatform
.