0

I have been trying to use the angular-file-upload here https://github.com/nervgh/angular-file-upload with typescript, and I keep getting this error:

TypeError: "Uploader" must be an instance of FileUploader I have to put a declare module and export namespace on the actual angular-file-upload to use modules(since that is how our framework was built) but I can't seem to go past this error

Don't worry about the module initialization or namespace names etc I should put placeholders there to not show our actual code.

Code below:

/// <reference types="angular" />
/// <reference types="angular-ui-bootstrap" />
/// <reference types="angular-file-upload"/>

var bootbox: any;

module MyModule.module {
    export class MyController  {
      
                

        static $inject = [
            "$scope",
            "$q",
            "$state",           
            "FileUploader"
               
        ];

        constructor(private scope: any,
            private promiseService: angular.IQService,
            private stateService: angular.ui.IStateService,          
            private uploader: angular.file.upload.FileUploader
            )                      
        {

            this.uploader.url = "upload.php";

            this.scope.uploader = this.uploader
}

(function () {
"use strict";
angular.module("myApp").controller("app.mymodule.controller", Namespace.MyApp.MyController);
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<input type="file" nv-file-select uploader="vm.uploader" /><br />

<ul>
  <li ng-repeat="item in uploader.queue">
    Name: <span ng-bind="item.file.name"></span><br />
    <button ng-click="item.upload()">upload</button>
  </li>
</ul>

0

2 Answers 2

0

Try instantiating the FileUploader with new angular.file.upload.FileUploader()

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

12 Comments

on the private uploader under the constructor signature? if yes that does not work lol
Whoops, my bad, did you try using new operator on the uploader in the class body? Or is the error happening on init?
yes I tried the one in the example but I guess since I am using example it is different, when I use the new I get an error that says Cannot use new with an expression whose type lacks a call or construct signature.
And what is the value that this.uploader has?
it does seem to be the fileuploader that I am setting it to, which is exported from the library. I do see all the methods like uploadAll, isHtml5 etc when i do a "this.uploader."
|
0

I fixed my issue, I was not using the interfaces correctly. Here is the correct code:

constructor(private scope: any,
  private fileUploaderFactory: angular.file.upload.FileUploaderFactory) {


  this.scope.uploader = new fileUploaderFactory({
    url: 'upload.php'
  });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.