angular-file-upload icon indicating copy to clipboard operation
angular-file-upload copied to clipboard

Inherit method seems to be invalid

Open larrybohn opened this issue 10 years ago • 3 comments

I've encountered the need to set some of the options for FileUpload globally for all instances, for example Authorization header. Setting the header in each controller where FileUpload service is used would be too repetitive. I followed the official FAQ and decorated the service:

$provide.decorator('FileUploader', ['$delegate', 'authenticationInterceptor', function (FileUploader) {
    FileUploader.inherit(AuthenticationAwareFileUploader, FileUploader);

    function AuthenticationAwareFileUploader(options) {
        angular.extend(options, {
            headers: {
                Authorization: getAuthorizationHeader()
            }
        });
        AuthenticationAwareFileUploader.super_.apply(this, arguments);
    }

    return AuthenticationAwareFileUploader;
}]);

And it's instantiating well, however, when I perform upload, a JS error is thrown to the console: Uncaught TypeError: this.constructor.isArrayLikeObject is not a function

I've found out that the inherit method is not working properly as constructor does not have all the necessary properties, though I'm not familiar with the syntax of your sources to provide more qualified details.

I was able to make it work properly my implementing the inheritance myself like that:

AuthenticationAwareFileUploader.prototype = FileUploader.prototype;
AuthenticationAwareFileUploader.super_ = FileUploader;

function AuthenticationAwareFileUploader(options) {
    angular.extend(options, {
        headers: {
            Authorization: getAuthorizationHeader()
        }
    });
    AuthenticationAwareFileUploader.super_.apply(this, arguments);
}

And this change should probably be propagated to the implementation of inherit like that:

        static inherit(target, source) {
            target.prototype = source.prototype;
            target.super_ = source;
        }

Please let me know what you think about it.

But in general, I think it would be much better to expose some configuration methods in FileUploaderProvider so that we can set it up at config phase without tricky overrides / inheritance.

larrybohn avatar Sep 23 '15 14:09 larrybohn

+1

seedy avatar Oct 21 '15 17:10 seedy

+1

pedrommuller avatar Jul 05 '16 00:07 pedrommuller

+1

ghost avatar Mar 07 '18 21:03 ghost