Skip to main content
se eliminaron 71 caracteres en el cuerpo
Origen Enlace
Checo
  • 107
  • 1
  • 2
  • 13
app.controller('ImagesCtrl', function ($scope, $timeout, $location, $window, $firebaseObject, $firebaseArray) {
    'use strict';
    window.scrollTo(0, 0);
    const REF = firebase.database().ref();

    
        $scope.thumbnail = {
        dataUrl: 'adsfas'
    };
    $scope.fileReaderSupported = window.FileReader != null;
    $scope.photoChanged = function(files){ 
        if (files != null) {
            for(let i=0; i>files.length; i++){
            let file = files[0];files[i];
            if ($scope.fileReaderSupported && file.type.indexOf('image') > -1) {
                $timeout(function() {
                    let fileReader = new FileReader();
                    fileReader.readAsDataURL(file);
                    fileReader.onload = function(e) {
                        $timeout(function(){
                $scope.thumbnail.dataUrl = e.target.result;
                let imgArr$scope.thumbnail.dataUrl = [];e.target.result;
                let img;
                img = imgArrconsole.pushlog($scopee.thumbnailtarget.dataUrlresult);
                for (var i = 0; i < imgArr.length; i++}) {;
                    console.log(imgArr[i]);
                }
 
                    });
                }
            });
        }
    };
     
});
});
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)" multiple/>
        <img ng-src="{{ thumbnail.dataUrl }}"/>
app.controller('ImagesCtrl', function ($scope, $timeout, $location, $window, $firebaseObject, $firebaseArray) {
    'use strict';
    window.scrollTo(0, 0);
    const REF = firebase.database().ref();

    
    $scope.thumbnail = {
        dataUrl: 'adsfas'
    };
    $scope.fileReaderSupported = window.FileReader != null;
    $scope.photoChanged = function(files){
        if (files != null) {
            let file = files[0];
        if ($scope.fileReaderSupported && file.type.indexOf('image') > -1) {
            $timeout(function() {
                let fileReader = new FileReader();
                fileReader.readAsDataURL(file);
                fileReader.onload = function(e) {
                    $timeout(function(){
                $scope.thumbnail.dataUrl = e.target.result;
                let imgArr = [];
                let img;
                img = imgArr.push($scope.thumbnail.dataUrl);
                for (var i = 0; i < imgArr.length; i++) {
                    console.log(imgArr[i]);
                }
 
                    });
                }
            });
        }
    }
    };
});
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)" multiple/>
        <img ng-src="{{ thumbnail.dataUrl }}"/>
app.controller('ImagesCtrl', function ($scope, $timeout, $location, $window, $firebaseObject, $firebaseArray) {
    'use strict';
    window.scrollTo(0, 0);
    const REF = firebase.database().ref();

    
        $scope.thumbnail = {
        dataUrl: 'adsfas'
    };
    $scope.fileReaderSupported = window.FileReader != null;
    $scope.photoChanged = function(files){ 
        if (files != null) {
            for(let i=0; i>files.length; i++){
            let file = files[i];
            if ($scope.fileReaderSupported && file.type.indexOf('image') > -1) {
                $timeout(function() {
                    let fileReader = new FileReader();
                    fileReader.readAsDataURL(file);
                    fileReader.onload = function(e) {
                        $timeout(function(){
                            $scope.thumbnail.dataUrl = e.target.result;
                            console.log(e.target.result);
                        });
                    }
                });
            }
        }
        }
    };
 
});
});
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)" multiple/>
        <img ng-src="{{ thumbnail.dataUrl }}"/>
Origen Enlace
Checo
  • 107
  • 1
  • 2
  • 13

Subir multiples imagenes AngularJS

Que tal, les pido su ayuda, quiero seleccionar imagenes en una sola carga, es decir que el usuario elija si quiere subir una sola imagen o mas de una. Lo estoy realizando de las siguiente manera:

app.controller('ImagesCtrl', function ($scope, $timeout, $location, $window, $firebaseObject, $firebaseArray) {
    'use strict';
    window.scrollTo(0, 0);
    const REF = firebase.database().ref();

    
    $scope.thumbnail = {
        dataUrl: 'adsfas'
    };
    $scope.fileReaderSupported = window.FileReader != null;
    $scope.photoChanged = function(files){
        if (files != null) {
            let file = files[0];
        if ($scope.fileReaderSupported && file.type.indexOf('image') > -1) {
            $timeout(function() {
                let fileReader = new FileReader();
                fileReader.readAsDataURL(file);
                fileReader.onload = function(e) {
                    $timeout(function(){
                $scope.thumbnail.dataUrl = e.target.result;
                let imgArr = [];
                let img;
                img = imgArr.push($scope.thumbnail.dataUrl);
                for (var i = 0; i < imgArr.length; i++) {
                    console.log(imgArr[i]);
                }

                    });
                }
            });
        }
    }
    };
});
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)" multiple/>
        <img ng-src="{{ thumbnail.dataUrl }}"/>

El problema es que solo me trae la primer imagen que selecciono, estoy intentando pasaras a un arreglo para después guardarlas en firebase. Muchas gracias!!