Guest User

Untitled

a guest
Jan 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <div class="container">
  2. <div ng-controller="MyCtrl" class="row">
  3. <button class="btn btn-primary pull-right" ng-hide="images.length == 0" ng-click="clearAll()">Clear All</button>
  4. <h3 ng-bind="name"></h3>
  5.  
  6. <input type="file" ng-click="$event = $event" ng-model="display" multiple onchange="angular.element(this).scope().upload(event)" accept="image/png, image/jpeg, image/gif" />
  7. <div class="row">
  8. <div class="col-md-12"> <span ng-repeat='img in images'> <a href="#" ng-click="setImage($index)">
  9. <img ng-src="{{img}}"
  10. alt="Generic placeholder thumbnail" style="max-height:100px;" class="thumbnail"/>
  11. </a>
  12.  
  13. </span>
  14.  
  15. </div>
  16. </div>
  17. <img ng-src="{{display}}" ng-hide="!display" />
  18. <h4>You have upload {{images.length}} images this session.
  19. </h4>
  20.  
  21. </div>
  22. </div>
  23.  
  24. var myApp = angular.module('myApp', []);
  25.  
  26. myApp.controller('MyCtrl', function ($scope) {
  27. $scope.name = "Select Files to Upload";
  28. $scope.images = [];
  29. $scope.display = $scope.images[$scope.images.length - 1];
  30. $scope.setImage = function (ix) {
  31. $scope.display = $scope.images[ix];
  32. }
  33. $scope.clearAll = function () {
  34. $scope.display = '';
  35. $scope.images = [];
  36. }
  37. $scope.upload = function (obj) {
  38. var elem = obj.target || obj.srcElement;
  39. for (i = 0; i < elem.files.length; i++) {
  40. var file = elem.files[i];
  41. var reader = new FileReader();
  42.  
  43. reader.onload = function (e) {
  44. $scope.images.push(e.target.result);
  45. $scope.display = e.target.result;
  46. $scope.$apply();
  47. }
  48. reader.readAsDataURL(file);
  49. }
  50. }
  51.  
  52. })
Add Comment
Please, Sign In to add comment