File Upload in Angular 4

前端 未结 6 578
我在风中等你
我在风中等你 2021-02-04 14:26

when I\'m trying to install \"npm install ng2-file-upload --save\" in my angular 4 application it throws

UNMET PEER DEPENDENCY @4.1.0
UNMET PEER DEPENDENCY          


        
6条回答
  •  不思量自难忘°
    2021-02-04 15:03

    I don't think we need some extra libraries

    onFileChange(event){
       let files = event.target.files; 
       this.saveFiles(files);
        }
    @HostListener('dragover', ['$event']) onDragOver(event) {
        this.dragAreaClass = "droparea";
        event.preventDefault();
    }
    @HostListener('dragenter', ['$event']) onDragEnter(event) {
        this.dragAreaClass = "droparea";
        event.preventDefault();
    }
    @HostListener('dragend', ['$event']) onDragEnd(event) {
        this.dragAreaClass = "dragarea";
        event.preventDefault();
    }
    @HostListener('dragleave', ['$event']) onDragLeave(event) {
        this.dragAreaClass = "dragarea";
        event.preventDefault();
    }
    @HostListener('drop', ['$event']) onDrop(event) {   
        this.dragAreaClass = "dragarea";           
        event.preventDefault();
        event.stopPropagation();
        var files = event.dataTransfer.files;
        this.saveFiles(files);
    }
    

    And now we are ready to upload files with drag and drop as well as by clicking the link button and upload extra data with files.

    See the complete article here Angular 4 upload files with data and web api by drag & drop

提交回复
热议问题