2016-11-13 9 views
0

ファイルオブジェクトをイメージオブジェクトに変換することはできますか?
私は(イメージです)ファイルから幅と高さを必要とするが、ここに私のコードです:AngularJS - ファイルオブジェクトをイメージオブジェクトに変換する

ビュー:

<button id="image_file" class="md-button md-raised md-primary" 
type="file" ngf-select="uploadFile($file)"> 
SELECT FILE 
</button> 

<md-input-container> 
<div class="raised"> 
<input id="image_file_name" type="text" ng-model="vm.file.name"></input> 
</div>  
</md-input-container> 

コントローラ:

app.controller('imageController', function($scope, fileService) { 

$scope.vm = {}; 

$('.intro').show(1000); 

$scope.uploadFile = function(file) { 
$scope.vm.file = ""; 
$scope.vm.file = file; //<---- for example here, how it should be done? 
    fileService.uploadFile($scope); 
} 

サービス:

angular.module('app') 
.service('fileService', function ($http, validationService) { 

     this.uploadFile = function ($scope){ 
     if (validationService.isFileValidate($scope)) { 
      $scope.vm.acceptableFormat = true; 
     } else { 
      $scope.vm.acceptableFormat = false; 
     } 

    }; 

    }); 
+0

ファイルはどのように選択されていますか?私は ''はどこですか? – Searching

+0

@ view 'コード'の上部にあるボタンを検索していますが、ここでng-file-uploadを使用しています – dante

+0

まだ動作していませんか? – Searching

答えて

0

ライブラリは、すでに必要としているもののほとんどを提供しているようです。ファイル/イメージの幅と高さのプロパティを読み込みます。

//Add accept option to filter only images 
<button id="image_file" class="md-button md-raised md-primary" 
type="file" accept="image/*" ngf-select="uploadFile($file)"> 
SELECT FILE 
</button> 

コントローラ

$scope.uploadFile = function(file) { 
$scope.vm.file = ""; 
$scope.vm.file = file;  
// show all file properties 
console.log(file); // Show available properties 
console.log(file.$ngfWidth +','+ file.$ngfHeight) // Your width and height 
fileService.uploadFile($scope); 

}

あなたは、おそらくそれはFeaturesですチェックアウトする必要があります。

関連する問題