Plugin is undefined on function call


#1

i’m not sure why $cordovaSocialSharing is showing up as undefined. perhaps some sort of async thing? here’s the code.

$scope.share = function(socialType, message, image, link) {
  console.log($cordovaSocialSharing);

  $cordovaSocialSharing.canShareVia(socialType).then(function(result) {
    console.log('result', result);
    $cordovaSocialSharing.share(message, 'subject', image, link);
  }, function(error) {
    console.log('error', error);
  });
}

the above function gives this error:

 TypeError: Cannot read property 'canShareVia' of undefined
at Object.canShareVia 

but that first console.log produces the object below with all the expected function names like canShareVia:

Object {share: function, shareViaTwitter: function, shareViaWhatsApp: function, shareViaFacebook: function, shareViaSMS: function…}canShareVia: function (r,t,o,i,a){var c=e.defer();return n.plugins.socialsharing.canShareVia(r,t,o,i,a,function(e){c.resolve(e)},function(e){c.reject(e)}),c.promise}canShareViaEmail: function (){var r=e.defer();return n.plugins.socialsharing.canShareViaEmail(function(){r.resolve(!0)},function(){r.reject(!1)}),r.promise}share: function (r,t,o,i){var a=e.defer();return n.plugins.socialsharing.share(r,t,o,i,function(){a.resolve(!0)},function(){a.reject(!1)}),a.promise}shareVia: function (r,t,o,i,a){var c=e.defer();return n.plugins.socialsharing.shareVia(r,t,o,i,a,function(){c.resolve(!0)},function(){c.reject(!1)}),c.promise}shareViaEmail: function (r,t,o,i,a,c){var u=e.defer();return n.plugins.socialsharing.shareViaEmail(r,t,o,i,a,c,function(){u.resolve(!0)},function(){u.reject(!1)}),u.promise}shareViaFacebook: function (r,t,o){var i=e.defer();return n.plugins.socialsharing.shareViaFacebook(r,t,o,function(){i.resolve(!0)},function(){i.reject(!1)}),i.promise}shareViaSMS: function (r,t){var o=e.defer();return n.plugins.socialsharing.shareViaSMS(r,t,function(){o.resolve(!0)},function(){o.reject(!1)}),o.promise}shareViaTwitter: function (r,t,o){var i=e.defer();return n.plugins.socialsharing.shareViaTwitter(r,t,o,function(){i.resolve(!0)},function(){i.reject(!1)}),i.promise}shareViaWhatsApp: function (r,t,o){var i=e.defer();return n.plugins.socialsharing.shareViaWhatsApp(r,t,o,function(){i.resolve(!0)},function(){i.reject(!1)}),i.promise}__proto__: Object