2017-03-04 3 views
2

の「socialsharing」プロパティを読み取ることができません:はTypeError:イオンとエラーを取得でアプリを作る未定義

TypeError: Cannot read property 'socialsharing' of undefined

は親切に私はエラーを取得してアプリケーションを共有するシンプルな画像を作る.Justを行って何を間違え私のコードをチェックしますソーシャルシェアリングプラグインで以下のコードを親切にチェックして、それを修正するために何をすべきか教えてください。

.controller('imageCtrl',function($scope,$cordovaSocialSharing,$http,$window) { 
    $scope.myImages = [ 
     {id :'1',image:'1.jpg'}, 
     {id :'2',image:'2.jpg'}, 

    ]; 

    $scope.getImagePath = function(imageName) { 
     return "img/" + imageName.image; 
    } 

    $scope.doit= function(index){ 
     console.log(index); 

    } 
    $scope.share = function(t, msg, img, link){ 
     if(t == 'w') 
      window.plugins.socialsharing 
       .shareViaWhatsApp(msg, img, link); 
     else if(t == 'f') 
      window.plugins.socialsharing 
       .shareViaFacebook(msg, img, link); 
     else if(t == 't') 
      window.plugins.socialsharing 
       .shareViaTwitter(msg, img, link); 
     else if(t == 'sms') 
      window.plugins.socialsharing 
       .shareViaSMS(msg+' '+img+' '+link); 
     else 
     { 
      var sub = 'Beautiful images inside ..'; 
      window.plugins.socialsharing 
       .shareViaEmail(msg, sub, ''); 
     } 
    } 
}); 

App.js

angular.module('starter', ['ionic','app.controllers','ngCordova']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 

     // Don't remove this line unless you know what you are doing. It stops the viewport 
     // from snapping when text inputs are focused. Ionic handles this internally for 
     // a much nicer keyboard experience. 
     cordova.plugins.Keyboard.disableScroll(true); 
    } 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 

HTML部分

<ion-content ng-controller="imageCtrl"> 
    <div ng-repeat="myImage in myImages" ng-click="doit($index)"> 
     {{myImage.id}} 
     <img class ="col item item-image thumbnail" ng-src="{{getImagePath(myImage)}}"/> 
     <div class="card gallary item item-divider"> 
      <div class="item item-text-wrap row"> 
       <button ng-click="share('w', '', myImage.image, '');" 
         class="button button-light col col-20"> 
        <i class="icon ion-social-whatsapp"></i> 
       </button> 
       <button ng-click="share('f', 'myMessage', myImage.image, '');" 
         class="button button-light col col-20"> 
        <i class="icon ion-social-facebook"></i> 
       </button> 
       <button ng-click="share('t', 'myMessage', myImage.image, '');" 
         class="button button-light col col-20"> 
        <i class="icon ion-social-twitter"></i> 
       </button> 
      </div> 
     </div> 
    </div> 
</ion-content> 

enter image description here

答えて

0

てみは$cordovaSocialSharingサービスを使用して、そのdocumentedのようなものです画像を確認してください。 shareViaEmail()canShareViaEmail()である必要があります。あなたは、代わりにこのif - if else - if else - if else - elseパターンのswitchを使用するつもりがあります

$scope.share = function(t, msg, img, link){ 
    switch (t) { 
     case "w": 
      $cordovaSocialSharing.shareViaWhatsApp(msg, img, link); 
      break; 
     case "f": 
      $cordovaSocialSharing.shareViaFacebook(msg, img, link); 
      break; 
     case "t": 
      $cordovaSocialSharing.shareViaTwitter(msg, img, link); 
      break; 
     case "sms": 
      $cordovaSocialSharing.shareViaSMS(msg + ' ' + img + ' ' + link); 
      break; 

     default: 
      $cordovaSocialSharing.canShareViaEmail(msg, 'Beautiful images inside ..', ''); 
      break; 
    } 
}; 

:これは、モバイルデバイス上ではなくデスクトップブラウザの場合に動作します。

+0

私はすでに同じエラーを試しています –

+0

試してみてください: 'console.log($ cordovaSocialSharing);'は未定義ですか? – lin

+0

それはまだ同じです.. –

関連する問題