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

App with Ionic + Polymer


npm install -g cordova ionic
ionic start myApp blank
cd myApp
bower install --save Polymer/polymer#^0.5
bower update
mkdir -p www/elements/my-element
subl www/elements/my-element/my-element.html

<link rel="import" href="../../bower_components/polymer/polymer.html">

<polymer-element name="my-element" attributes=""> <template>

<span>Hello from <b>my-element</b>.

</template>
<script>
(function () {
Polymer({
// define element prototype here
});
})();
</script>
</polymer-element>

subl www/index.html

...
<head>
...
<link rel="import" href="lib/polymer/polymer.html">
<script src="lib/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="elements/my-element/my-element.html">
...
<body>
...
<my-element></my-element>
...
</body>
</html>

ionic serve