2017-05-25 10 views
0

これは私のHTMLフォーム

<form ng-submit='create()'> 
    .. 
    . 
    . 
    <input type='file' ng-model='logo' accept="image/*"> 
</form> 

が、これは私のコントローラです。

$scope.create = function() { 
     $scope.Ent = {} 
     $scope.Ent.logo = $scope.logo; 

This is my console only input file is undefined and all other fileds are alright

+0

の可能性のある重複した[用NG-モデルの](httpsにスコープ変数を割り当てるバインドするカスタムディレクティブを使用.com/questions/17063000/ng-model-for-input-type-file) – quirimmo

答えて

1

ng-modelは、入力タイプ「ファイルでは動作しません。 // stackoverflowの:それは

.directive("fileread", [function() { 
    return { 
     scope: { 
      fileread: "=" 
     }, 
     link: function (scope, element, attributes) { 
      element.bind("change", function (changeEvent) { 
       var reader = new FileReader(); 
       reader.onload = function (loadEvent) { 
        scope.$apply(function() { 
         scope.fileread = loadEvent.target.result; 
        }); 
       } 
       reader.readAsDataURL(changeEvent.target.files[0]); 
      }); 
     } 
    } 
}]); 

fileread属性

<form ng-submit='create()'> 
    .. 
    . 
    . 
    <input type='file' fileread='logo' accept="image/*"> 
</form> 
+0

すでに問題を説明している記事を見つけたら、正確に同じコードをコピーして貼り付けるのではなく、重複としての質問:https://stackoverflow.com/questions/17063000/ng-model-for-input-type-file psまたは少なくとも答えのその記事を参照してください – quirimmo

+1

それは非常に有用ですありがとう –

関連する問題