asafdav / ng-csv

Simple directive that turns arrays and objects into downloadable CSV files
MIT License
573 stars 215 forks source link

ng csv :lazy load triggering before promise gets resolved. #130

Closed shyamg91 closed 8 years ago

shyamg91 commented 8 years ago

I'm getting the data for the csv through an api call and hence am using lazy load to ensure that the data is received. However it is getting triggered before.

                <div type="button" ng-csv="getStudentData()" lazy-load="true" filename="test.csv" csv-header="studenttableHeader">EXPORT</div>

This is how my controller is set up :

$scope.getStudentData = function () { return lazyloadexport; }

edit : Exportstudents is a http get request which returns data .

function lazyloadexport() {
    var deferred = $q.defer();
    Auth.exportStudents($scope.filterCode.filter).then(function (data) {
        $q.when(data).then(function () {
            deferred.resolve(data);
        });
    }, function (err) {
        deferred.reject(err);
    });
    return deferred.promise;
}

This is what i understood was needed to make promises work. What am i doing wrong ?

daniel-van-niekerk commented 8 years ago

Why was this closed? I have the same problem.