cordova – 使用离子框架从android中的图库中显示图像

你好我正在尝试开发 Android应用程序来加载图像库中的图像.这是代码snipet.我无法显示图像.有人可以指出我哪里出错了吗?

*.html的

<ion-view title="Account">
  <ion-content class="has-header padding">
    <h1>Upload Image</h1>
      <div class="account-picture">
          <button ng-click="ShowPictures()">Select Picture</button>
          <img src="ImageURI" id="smallimage">
          <input type="text" ng-model="ImageURI" size="30"/>
      </div>
  </ion-content>
</ion-view>

Controller.js

.controller('AccountCtrl',function($scope) {

    $scope.ImageURI = 'Select Image';
    function UploadPicture(imageURI) {

        $scope.ImageURI =  imageURI;
        alert($scope.ImageURI );
    }

    $scope.ShowPictures = function() {
        navigator.camera.getPicture(UploadPicture,function(message) {
                alert('get picture failed');
            },{
                quality: 50,destinationType: navigator.camera.DestinationType.FILE_URI,sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
            }
        );
    };
});

在这里ia ImageURI我正在接收afetr从图库中选择任何文件:content:// media / external / images / media / 17.我盲目地为我的图像src硬编码了这个值.但我没有看到任何.这里有什么输入?

此外,ImageURI也没有绑定我的文本框.警报正确显示URI.

它看起来非常直接使用普通的phonegap应用程序.但我不喜欢离子框架.

解决方法

你需要调用$scope.$apply();告诉angular你的异步功能已经完成.也

$scope.ImageURI =  imageURI;
$scope.$apply();

另外 – 你可能会遇到和我一样的问题 – 请参阅上面的评论.

相关文章

公司前端界面用的是vue,我要嵌入到Android中生成App第一步:...
Q:我用cordova开发项目,想在app内跳转外部链接,安装了cord...
我正在使用https://github.com/arnesson/cordova-plugin-fir...
一、Cordova的基础点在混合式应用中,我们通过现有的Cordova...
cordova自定义插件注意:存放自定义cordova插件目录不能有空...
一、问题VueAPP中有一个文件下载功能,用了各种方法来实现下...