I\'m a beginner with Angular, I want to know how to create Angular 5 File upload part, I\'m trying to find any tutorial or doc, but I don\'t see anything a
Ok, as this thread appears among the first results of google and for other users having the same question, you don't have to reivent the wheel as pointed by trueboroda there is the ng2-file-upload library which simplify this process of uploading a file with angular 6 and 7 all you need to do is:
Install the latest Angular CLI
yarn add global @angular/cli
Then install rx-compat for compatibility concern
npm install rxjs-compat --save
Install ng2-file-upload
npm install ng2-file-upload --save
Import FileSelectDirective Directive in your module.
import { FileSelectDirective } from 'ng2-file-upload';
Add it to [declarations] under @NgModule:
declarations: [ ... FileSelectDirective , ... ]
In your component
import { FileUploader } from 'ng2-file-upload/ng2-file-upload';
...
export class AppComponent implements OnInit {
public uploader: FileUploader = new FileUploader({url: URL, itemAlias: 'photo'});
}
Template
For better understanding you can check this link: How To Upload a File With Angular 6/7