0

I want to show progress of the file upload (file reader).

Here is my html:

<md-progress-linear id="file-progress-indicator" md-mode="determinate" value="{{progress}}"></md-progress-linear>

and here is my directive:

angular.module('image.directives').directive('edFileUploader', ['$parse', '$mdDialog', '$mdBottomSheet', '$timeout', 'toastr', function($parse, $mdDialog, $mdBottomSheet, $timeout, toastr) {

    return {
        restrict: 'A',
        link: function($scope, el, attrs) {
            var setter = $parse(attrs.edFileUploader)($scope);

            $(el[0]).on('change', function(e) {

                var reader = new FileReader();

                    if (setter) {
                        setter(event.target.result, el);

                        if (typeof attrs.edCloseAfter !== 'undefined') {
                            $mdBottomSheet.hide();
                        }
                    }
                };

                reader.onprogress = function(data) {
                    if (data.lengthComputable) {
                        var progress = parseInt(((data.loaded / data.total) * 100), 10);
                        // $scope.progress = progress;
                    }
                }

                if (e.target.files[0] != undefined) {
                    reader.readAsDataURL(e.target.files[0]);
                    $scope.loading = false;
                    el.next().removeClass('loading');
                    $scope.done = true;
                } else {
                    $scope.loading = false;
                    el.next().removeClass('loading');
                    $scope.done = true;
                }
            });

        }
    }
}]);

How to pass variable progress from the reader.onprogress so that it progress bar would work as expected?

1

1 Answer 1

0

See this: (http://jsfiddle.net/L8masomq/)

Here we use the method for sending data from direcctive to controller. Here Test is the element directive and attribute is data-method="ctrlFn"

may this help,

Sign up to request clarification or add additional context in comments.

1 Comment

This actually helped. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.