This question already has an answer here:
I use the following example, it works perfectly , but I'd like to upload multiple images simultaneously.
http://jsfiddle.net/kkhxsgLu/2/
<div ng-controller="MyCtrl">
<div ng-repeat="step in stepsModel">
<img class="thumb" ng-src="{{step}}" />
</div>
<input type='file' ng-model-instant onchange="angular.element(this).scope().imageUpload(this)" />
$scope.stepsModel = [];
$scope.imageUpload = function(element){
var reader = new FileReader();
reader.onload = $scope.imageIsLoaded;
reader.readAsDataURL(element.files[0]);
}
$scope.imageIsLoaded = function(e){
$scope.$apply(function() {
$scope.stepsModel.push(e.target.result);
});
}
Thank you kindly help me, I started with angularjs
Directive to get files input with
ng-model
(multiple files)The AngularJS built-in
<input>
directive does not handle<input type=file>
. One needs a custom directive for that.The
files-input
directive:The above directive adds a change listener that updates the model with the files property of the
input
element.This directive enables
<input type=file>
to automatically work with theng-change
andng-form
directives.The DEMO on PLNKR
Inline Demo of
files-input
DirectiveSOLUTION:
http://jsfiddle.net/orion514/kkhxsgLu/136/
:)
Zypps987, try using var file = files[0], not inside a loop.