我正在開發一個使用Ionic/Angular JS的應用程序。在我使用ngCordova Camera Plugin的特定頁面中,用戶可以從手機的圖庫中選擇圖片。 現在,我不知道如何在應用程序用戶選擇圖片後在頁面中顯示圖片。下面是HTML代碼:Ionic/Angular JS - 使用ngCordova Camera Plugin選擇它後顯示圖片
<div class="row">
<div class="select-photo" ng-click="selectPicture()">Select Picture</div>
<div class="photo-display"> <!-- Display Photo Here --> </div>
</div>
這裏是我使用的特定選項卡控制器JS:
.controller('PetitionsCtrl', function($scope, $cordovaGeolocation, $cordovaCamera, $log, $ionicLoading, $http, $timeout, $compile) {
document.addEventListener("deviceready", function() {
$scope.selectPicture = function() {
var options = {
quality: 90,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}, function(err) {
// error
});
}
}, false);
})
有人能幫助我嗎?
不確定您是否需要eventListener,ngclick會相應地處理事件。另外,或者我認爲Ionic可能有一個點擊事件。 – alphapilgrim