Reputation: 123
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 ?
Upvotes: 0
Views: 77
Reputation: 15752
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/
Upvotes: 1