Above npm package details are to be renamed ng2-fileupload to ngx-fileupload with the name change of the npm package.
Simpler file upload implementation for angular apps.
To install this library, implement the following:
npm install @99xt/ngx-fileupload --saveThis is to be updated to ngx-fileupload
example.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ExampleComponent } from './example.component';
// Import the library
import { FileUploadModule } from '@99xt/ngx-fileupload';
/** This is to be updated to ngx-fileupload*/
@NgModule({
declarations: [
ExampleComponent
],
imports: [
BrowserModule,
FileUploadModule
],
providers: [],
bootstrap: [ ExampleComponent ]
})
export class ExampleModule { }example.component.ts
export class ExampleComponent {
allowedTypes: any;
allowedSize: number;
multiple: boolean;
files: any;
constructor() {
this.allowedTypes = [ 'text/markdown' ];
this.allowedSize = 15; // MB
this.multiple = true;
}
onUploadFiles(evt: any) {
if (evt.error) {
throw evt.error;
}
const files = evt.files;
// You can run upload script here
}
}example.component.html
<file-upload
[allowedTypes]="allowedTypes"
[allowedSize]="allowedSize"
[multiple]="multiple"
(onUploadFiles)="onUploadFiles($event)"
>
</file-upload>Make sure you have the @angular/cli latest version and its Prerequisites installed globally. For more info Check Angular CLI.
Clone the repository to your workstation
git clone git@github.com:99xt/ngx-fileupload.gitNavigate to the project directory
cd ngx-fileuploadnpm installRun ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.
Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the -prod flag for a production build.
Run ng test to execute the unit tests via Karma.
Run ng e2e to execute the end-to-end tests via Protractor.
Before running the tests make sure you are serving the app via ng serve.
To get more help on the Angular CLI use ng help or go check out the Angular CLI README.