Fatih Akboyun
Fatih Akboyun

Reputation: 26

TypeError: $scope.resetDropzone is not a function

I want to reset my dropZone area by clicking reset button but I can not call resetDropzone function(in directivejs) from my controller. Can you help me please My directive.js is:

function dropZone() {
console.log("access");
return {
    restrict: 'C',
    link: function (scope, element, attrs) {

        var config = {
            url: 'http://localhost:8080/upload',
            maxFilesize: 100,
            paramName: "uploadfile",
            maxThumbnailFilesize: 10,
            parallelUploads: 1,
            autoProcessQueue: false
        };

        var eventHandlers = {
            'addedfile': function (file) {

                scope.file = file;
                if (this.files[1] != null) {
                    this.removeFile(this.files[0]);
                }
                scope.$apply(function () {

                    scope.fileAdded = true;
                });
            },

            'success': function (file, response) {
            }

        };

        dropzone = new Dropzone(element[0], config);

        angular.forEach(eventHandlers, function (handler, event) {
            dropzone.on(event, handler);
        });

        scope.processDropzone = function () {
            dropzone.processQueue();
        };

        scope.resetDropzone = function () {
            console.log("resetDropzon mthd");
            dropzone.removeAllFiles();
        };
    }
}

}

I call this function from html code as ng-click="reset()" and my controller is:

$scope.reset = function () {
    console.log("reset mthd");
    $scope.resetDropzone();
};

Upvotes: 0

Views: 2008

Answers (1)

Lazar Yanchev
Lazar Yanchev

Reputation: 101

resetDropzone() resides in the isolated scope of your directive. You can't call it from your controller scope.

Here you can find an example how to achieve your scenario. How to call a method defined in an AngularJS directive?

Bind your directive to an object in your controller scope and define resetDropzone method to this object. You will be able to call it from the controller.

Upvotes: 1

Related Questions