In this blog, I am going to tell you that how to create directive for read file from html in angular js.
If I want to upload a file in our project then we need to read file from form after then we need to upload file.
There are two ways to select file to use :-
1.<input type = 'file'>
2.Drag and down a file into broser.
This directive is used for the file input.
For read file,a directive is given below:-
angular.module('urbanApp').directive("fileread", [function () { return { scope: { fileread: "=" }, link: function (scope, element, attributes) { element.bind("change", function (changeEvent) { scope.$apply(function () { scope.fileread = changeEvent.target.files[0]; // or all selected files: // scope.fileread = changeEvent.target.files; }); }); } } }])
I hope this blog will help you.
THANKS
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Murari Kumar
Murari is a bright Web developer. He has expertise in Java.