0

I am trying to upload file using angularJS. The problem is I would like to follow good practices and use code like this in my controller:

var vm = this;
vm.uploadFile = uploadFile;

But it makes hard for me to upload files, because every answer I found is based on $scope and I can not modify it to make it work with vm.

How can I make following code work with vm?

<input type="file" name="file"  onchange="angular.element(this).scope().uploadFile(this.files)">

In my controller.js

 function uploadFile(files) {
    //working code proccessing file
  };

How can I make provided html work ?

1 Answer 1

1

I suggest you use a ready-made boilerplate, like ng-file-upload. In our project it works like a charm:

Npm

https://www.npmjs.com/package/ng-file-upload

Demo

https://angular-file-upload.appspot.com/

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

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.