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 @4.1.0
`-- [email protected]
and upload is not working my applications throws
"Can't bind to 'uploader' since it isn't a known property of 'input'"
this is my HTML
<input type="file" ng2FileSelect [uploader]="upload" multiple formControlName="file" id="file"/>
and its Component
import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
import { FileSelectDirective, FileUploader } from 'ng2-file-upload/ng2-file-
upload';
export class PersonalInfoComponent implements OnInit
{
public upload:FileUploader= new FileUploader({url:""});
}
Parent Module
import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
@NgModule({
imports: [
..
....
..
FileUploadModule
],
export class RegistrationModule { }
and I didn't Import/change anything in AppModule(Grand Parent Module).
can someone help me on this please...
The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute. Tip: Always add the <label> tag for best accessibility practices!
Upload images in Angular 4 without a plugin This is the article that might be worth trying. Upload images in Angular 4 without a plugin
It emphasize on these points:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With