show a message of Loading ... ** Angular **

1

I have a download of a PDF document, currently there are times that it takes to make the request and I do not know how to see what state the request is in to show a loading message.

function downloadPDF () {
        $log.debug('btn descargar PDF');

        var url = Constants.BaseURLBack + '/mir/reportes/matriz?idMir=' + idMir;
        RestService.getFile(url,'application/pdf')
        .then(function(response) {
            var blob = new Blob([response.data], { type: "application/pdf" });
            saveAs(blob, "matriz.pdf");        
        })
        .catch(function(err){
            message("error","Excel sin datos","Por favor seleccione un proyecto con datos");
            console.log("Error al descargar el excel", err);
        });

    }
    
asked by wootsbot 24.02.2017 в 18:03
source

1 answer

2

You can put a loading GIF next to the button in your html:

<img ng-if="mostrarCargando" src="imagenes/cargando.gif"/>

and you give values before and after the download:

function downloadPDF() {
    $log.debug('btn descargar PDF');
    $scope.mostrarCargando = true;

    var url = Constants.BaseURLBack + '/mir/reportes/matriz?idMir=' + idMir;
    RestService.getFile(url, 'application/pdf')
    .then(function (response) {
        var blob = new Blob([response.data], { type: "application/pdf" });
        saveAs(blob, "matriz.pdf");
    })
    .catch(function (err) {
        message("error", "Excel sin datos", "Por favor seleccione un proyecto con datos");
        console.log("Error al descargar el excel", err);
    });
    $scope.mostrarCargando = false;
}
    
answered by 24.02.2017 / 18:25
source