2
製作應用程序的特性「socialsharing」和得到的錯誤:類型錯誤:無法讀取離子未定義
TypeError: Cannot read property 'socialsharing' of undefined
請檢查我的代碼,我做了什麼錯。只是做一個簡單的圖片共享應用程序在那裏我得到的錯誤關於社交分享插件,請檢查下面的代碼,並建議我該怎麼做才能糾正該問題。
.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>
仍然同樣的錯誤,我已經嘗試 –
嘗試:'console.log($ cordovaSocialSharing);'它是不確定的? – lin
沒有它仍然相同.. –