FileDownloader
This library was generated with Angular CLI version 15.2.0.
Usage
-
Import the FileDownloaderModule:
import { FileDownloaderActionModule } from 'file-downloader-action';
Import the FileDownloaderModule into the module where you intend to use the <app-file-downloader-action> component. For example, in your AppModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FileDownloaderModule } from 'file-downloader-action';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FileDownloaderActionModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
-
Configure the ApiRequest:
Define an ApiRequest object to specify the file to download:
import { ApiRequest } from 'http-request-manager';
apiFileRequest = ApiRequest.adapt({
server: '',
path: ['assets', 'icons.svg'],
});
-
Use the component in your template:
<app-file-downloader-action
[apiRequest]="apiFileRequest"
[displayErrorMessage]="true"
(completed)="onCompleted()"
></app-file-downloader-action>
[apiRequest]: The ApiRequest object. Specify server and path (file path and name)
[displayErrorMessage]: Display error message only as a toast-message.
(completed): An event that emits when the download completes.
-
Handle the completed event (optional):
onCompleted() {
console.log('Download completed!');
}
Complete Example:
import { Component } from '@angular/core';
import { ApiRequest } from 'http-request-manager';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
apiFileRequest = ApiRequest.adapt({
server: '',
path: ['assets', 'icons.svg'],
});
onCompleted() {
console.log('Download completed!');
}
}
<app-file-downloader-action
[apiRequest]="apiFileRequest"
[displayErrorMessage]="true"
(completed)="onCompleted()"
></app-file-downloader-action>