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

Vam*_*lli 5 phonegap-plugins cordova ionic-framework

你好我正在尝试开发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>
Run Code Online (Sandbox Code Playgroud)

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
            }
        );
    };
});
Run Code Online (Sandbox Code Playgroud)

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

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

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

joe*_*iks 4

你需要调用 $scope.$apply(); 告诉 Angular 你的异步函数已经完成。还

$scope.ImageURI =  imageURI;
$scope.$apply(); 
Run Code Online (Sandbox Code Playgroud)

另外 - 你可能会遇到与我相同的问题 - 请参阅我上面的评论。