file-downloader-action
v18.0.4
Published
This is an Angular Module containing Components/Services using Material
Downloads
353
Readme
FileDownloader
This library was generated with Angular CLI version 15.2.0.
Usage
Import the
FileDownloaderModule:import { FileDownloaderActionModule } from 'file-downloader-action';Import the
FileDownloaderModuleinto the module where you intend to use the<app-file-downloader-action>component. For example, in yourAppModule: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
ApiRequestobject to specify the file to download:import { ApiRequest } from 'http-request-manager'; apiFileRequest = ApiRequest.adapt({ server: '', // Base URL of your server. Leave blank if the path is absolute. path: ['assets', 'icons.svg'], // The path to the file. });Use the component in your template:
<app-file-downloader-action [apiRequest]="apiFileRequest" [displayErrorMessage]="true" (completed)="onCompleted()" ></app-file-downloader-action>[apiRequest]: TheApiRequestobject. Specifyserverandpath(file path and name)[displayErrorMessage]: Display error message only as a toast-message.(completed): An event that emits when the download completes.
Handle the
completedevent (optional):onCompleted() { console.log('Download completed!'); // Add any logic you want to execute after the download finishes }
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>