Ionic ngCordova social-sharing


ionic start ionic-ngcordova-social-sharing blank
cd ionic-ngcordova-social-sharing
bower install ngCordova
cordova platform add android
cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git
in index.html change to following:
<head>
...
< script src="lib/ngCordova/dist/ng-cordova.js" > < /script >
...
</head>
....
<body ng-controller="AppCtrl" >
....
<ion-content>
<textarea placeholder="Comments" ng-model="comments"></textarea>
<button class="button button-full button-positive" on-click="share()" on-tap="share()">
Share
</button>
<button class="button button-full button-positive" on-tap="shareByEmail()">
Share By Email
</button>

</ion-content>

...
</body>
...

in app.js change following:

angular.module('starter', ['ionic','ngCordova'])
...
.run(...
...
).controller('AppCtrl', function($scope, $cordovaSocialSharing) {$scope.comments = "";
$scope.share = function() {
$cordovaSocialSharing
.share($scope.comments, "My comment") // Share via native share sheet
.then(function(result) {
// Success!
}, function(err) {
// An error occured. Show a message to the user
});
}
$scope.shareByEmail = function() {

$cordovaSocialSharing
.shareViaEmail($scope.comments, "My comment", "someone@example.com")
.then(function(result) {
// Success!
}, function(err) {
// An error occurred. Show a message to the user
});
}
});

ionic build --android

ionic run --emulator

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s