0x3d.Site
is designed for aggregating information.
check repository here
ngx-filesaver
Simple file save with FileSaver.js
Examples
Installation
$ npm install file-saver ngx-filesaver
# Or when using yarn
$ yarn add file-saver ngx-filesaver
# Or when using pnpm
$ pnpm install file-saver ngx-filesaver
Add the FileSaverModule
module to your project:
import { FileSaverModule } from 'ngx-filesaver';
@NgModule({
imports: [FileSaverModule],
})
export class AppModule {}
Instructions
There are two ways to save a file: using FileSaverService.save()
or using the fileSaver
directive.
1、FileSaverService
constructor(private _http: Http, private _FileSaverService: FileSaverService) {
}
onSave() {
this._http.get('demo.pdf', {
responseType: ResponseContentType.Blob // This must be a Blob type
}).subscribe(res => {
this._FileSaverService.save((<any>res)._body, fileName);
});
}
2、fileSaver directive
Configuration example
<button
type="button"
fileSaver
[method]="'GET'"
[fileName]="'中文pdf.pdf'"
[url]="'assets/files/demo.pdf'"
[header]="{ token: 'demo' }"
[query]="{ pi: 1, name: 'demo' }"
(success)="onSuc($event)"
(error)="onErr($event)"
>
Download PDF
</button>
fileSaver: the directive name Parameters
Parameter | Description | Type | Default |
---|---|---|---|
method | Request method type | string | GET |
url | Request URL | string | - |
fileName | Filename when downloading | string | - |
query | Additional query parameters. Equivalent to params value | string | - |
header | Header configuration. Usually used for especifying access tokens | any | - |
fsOptions | FileSaver.js config, can be set autoBom value | FileSaverOptions | - |
success | Download success callback | EventEmitter<HttpResponse<Blob>> | - |
error | Download error callback | EventEmitter<any> | - |
Custom HTTP type
<button type="button" fileSaver [http]="onRemote('pdf', true)">Download PDF</button>
onRemote(type: string, fromRemote: boolean): Observable<Response> {
return this._http.get(`assets/files/demo.${type}`, {
responseType: ResponseContentType.Blob
}).map(response => {
response.headers.set('filename', `demo.${type}`)
return response;
});
}
About filenames
The name for the downloaded file is obtained with the following priority:
- fileName
- response.headers.get('filename')
- response.headers.get('x-filename')。
If you are requesting a CORS address, you need to pay attention to the request headers. Setting Access-Control-Allow-Headers: filename
should be sufficient
Class Name
Class Name | Description |
---|---|
filesaver__not-support | Not Supported Browsers |
filesaver__disabled | During http request |
Configuring CommonJS dependencies
WARNING in node_modules/ngx-filesaver/ivy_ngcc/fesm2015/ngx-filesaver.js depends on file-saver. CommonJS or AMD dependencies can cause optimization bailouts.
We cannot change this, the only way is to ignore it:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [
"file-saver"
]
...
}
...
},
Angular
Angular is a popular framework for building dynamic web applications using TypeScript. It provides tools for creating single-page applications (SPAs) with rich user interfaces. Known for its robust architecture, Angular is widely used in enterprise development.
rxjs-fruits.com
Angular Developer Roadmap: Learn to become a Angular developer
Join the Angular Community Discord Server!
Newsletter
thePunderWoman 🏳️🌈 (@[email protected])
Angular University
ZITADEL with Angular | ZITADEL Docs
Angular Air
ngx.tools: Angular Packages Discovery
justangular.com
NgServe.io - Serving the Angular and Web Developer Community
Angular - Halodoc Blog
Tomasz Ducin - blog
Translate Angular app with AI - GlobalSeo
axe Accessibility Linter - Visual Studio Marketplace
Practical Angular Newsletter by Angular Mentor
Angular-Buch → Entwickeln Sie moderne Apps für Web und Mobile.
Angular Experts Podcast - Angular Experts
Home
Angular on Netlify
simplified Angular Blog
Angular posts on daily.dev
Analog | Analog
katsuba.dev
Frontend Handbook | Angular / Introduction
Angular Material
webpack
Accessibility for teams
Learn how to build apps with modern reactive and declarative code
Angular
More on Angular
Programming Tips & Tricks
Code smarter, not harder—insider tips and tricks for developers.
Using Lua's Garbage Collector for Fine-Tuned Memory Management in Large Applications
#1
Leveraging Lua's Environment for Dynamic Code Execution and Security
#2
Mastering Lua's Table Manipulation: Advanced Techniques for Handling Large Data Sets
#3
Enhancing Code Readability and Debugging with Lua's Debug Library
#4
Leveraging Lua's Coroutines for Efficient Concurrency and Asynchronous Programming
#5
Leveraging Lua's Tail Call Optimization for Efficient Recursion and Avoiding Stack Overflow in Deep Recursive Functions
#6
Creating Custom Iterators in Lua for Traversing Complex Data Structures Like Graphs or Trees
#7
How to Maximize the Speed of Data Lookup in Lua Using Hash Tables and Optimized Table Management
#8
Advanced Techniques for Asynchronous Programming in Lua Using Coroutines for High-Performance Systems
#9
Mastering Efficient Memory Management in Lua with Weak Tables for Optimal Resource Utilization
#10
Error Solutions
Turn frustration into progress—fix errors faster than ever.
Visual Studio Crashes When Opening a File or Debugging a Project
#1
Visual Studio Cannot Connect to GitHub or Other Version Control System
#2
Visual Studio Freezes During Build or Debug Process
#3
Visual Studio Fails to Build Project with "Unable to Start Program" Error
#4
Visual Studio Shows "Cannot Open the Solution" Error Message When Opening a Project
#5
Visual Studio Crashes on Startup with "The application has encountered an error" Message
#6
Visual Studio Fails to Detect Changes in Files When Using Git Integration
#7
Visual Studio Crashes with "Unknown Exception" When Trying to Build Solution
#8
Visual Studio Hangs During Debugging with "Unable to Start Program" Error
#9
Visual Studio Fails to Load Solution with "The system cannot find the file specified" Error
#10
Shortcuts
The art of speed—shortcuts to supercharge your workflow.
Maximize Your Code Navigation with Cmd + Option + Left Arrow!
#1
Feel Like a Pro with Cmd + Control + D: Quickly View Definitions Like Never Before!
#2
Unlock Speed and Precision with Cmd + Shift + M: Maximize Your Productivity!
#3
Don’t Panic, Use Cmd + Option + I to Open the Developer Tools Now!
#4
Stop Wasting Time and Jump to Your File in an Instant with Cmd + Shift + O!
#5
Quickly Fix Your Code with ‘Cmd + Option + L’ for Instant Code Formatting!
#6
Transform Your Workflow with ‘Cmd + Shift + N’ to Open a New Window in No Time!
#7
Say Goodbye to Mouse: Master ‘Cmd + Shift + F’ to Search Your Entire Codebase!
#8
Struggling to Find Files? Hit ‘Cmd + P’ and Jump Right to Your File!
#9
Never Lose Your Progress Again: Use ‘Cmd + Z’ to Undo Mistakes Instantly!
#10
Made with ❤️
to provide resources in various ares.