Drag And Drop In Angular 2
Posted By : Damandeep Singh | 20-Mar-2018
What happens when you are working with Angular 2+ and you want to add a functionality of Drag and Drop file Upload. I found several Solutions to this problem, and many seem a bit intimidation for a beginner While tackling this problem I found a plugin named fileDroppa provided by
Here is a single basic command to add fileDroppa to your Project
i.e,
Using this Command the Package name will be automatically added to our Package.
Now Import the package
Here is the basic Syntax of fileDroppa
<fileDroppa [url]="'https://180.154.20.01/image/upload_file'"
[autoUpload]="false"
[showFilesList]="true"
[beforeRequest]="beforeRequest"
[beforeFileUpload]="beforeFileUpload"
[beforeAddFile]="beforeAddFile"
(filesUpdated)="filesUpdated($event)"
(fileUploaded)="fileUploaded($event)">
</fileDroppa>
Here is the brief of Required Parameters in fileDroppa
- URL: it is required to make Post Request
- AutoUpload: If it is True files will be automatically uploaded once Selected or Dropped
- ShowFilesList: If False files will be hidden
- BeforeRequest: callback which is called before File will be posted to a server. Good chance to set request header or update XHR request
- BeforeFileUpload: callback which is
- the called before the specific file is uploaded, called with a formData object.
- BeforeAddFile: callback which is called once you drop or select file and before a file is added to fileDroppa
file store. It can be used to validate file for example by its type or size.
-
Multiple : If True set multipleattribute of hiddenfile file tag.Default True.
-
-
-
FilesUpdated Callback which will be fired once when files are updated.:
-
-
-
-
-
-
-
-
-
FileUploaded : Callback which will be fired once when file uploaded Successfully.
-
-
-
-
-
-
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
Damandeep Singh
Damandeep Singh is a Front-end Developer having Good knowledge of HTML, CSS3/CSS, Bootstrap, Angular, Ionic. He likes to listen to Music in Free time.