danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

Annotate with ngInject instead #1901

Open n1kos opened 7 years ago

n1kos commented 7 years ago

Ok, not sure if this is actually an issue, but can't find any information on the subject

When you DI using the angular annotation ie

angular.module("app") .controller("ctrl", ["d1", "d2", "Upload", function(d1, d2, $upload){ $upload }])

everything works fine. But, when you try to use ngInject, ie

angular.module('app").controller("ctrl", ctrl); /** @ngInject */ function ctrl(d1, d2, Upload) { $upload } $upload is undefined. Is there a way to reference Upload as $upload? (ReferenceError: $upload is not defined, on file.upload = $upload.upload())

Thanks

ssudaraka commented 7 years ago

This won't work because in the first method you can explicitly say that use "Upload" as $upload. However, in the second method, you can't. Still, you can inject the Upload as this if you really really want to refer it as $upload even though I'm not recommending it.

/** @ngInject */
function ctrl(d1, d2, Upload) {
    var $upload = Upload;
}
n1kos commented 7 years ago

Actually I tried that as well, it didn't work either.