Created
October 10, 2012 15:37
-
-
Save Enome/3866401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var controllers = { | |
UploadCtrl: function ($scope) { | |
$scope.images = []; | |
$scope.files = []; | |
$scope.upload = function (element) { | |
$scope.$apply(function ($scope) { | |
$scope.files = element.files; | |
}); | |
}; | |
$scope.$watch('files', function () { | |
for (var i = 0; i < $scope.files.length; i += 1) { | |
var current = $scope.files[i]; | |
var reader = new FileReader(); | |
reader.onload = (function (file) { | |
return function (env) { | |
console.log(file.name); | |
$scope.images.push({ name: file.name, src: env.target.result }); | |
} | |
}(current)); | |
reader.readAsDataURL(current); | |
} | |
}); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-controller='UploadCtrl'> | |
<input type='file' multiple onchange='angular.element(this).scope().upload(this)' /> | |
<div ng-repeat='image in images'> | |
{{image.name}}: <img ng-src='{{image.src}}' width='80' height='80' /> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment