Shardul
Shardul

Reputation: 405

Creating log file in angular 2

I am relatively new to both Angular 2 and typescript. I want to create a log file in angular 2. Can it be possible using angular 2.

Upvotes: 3

Views: 4706

Answers (1)

Runtime Terror
Runtime Terror

Reputation: 6752

For that you will need a package like FileSaver.js

First, you need to install the package itself: npm install file-saver --save

The definition files as well: npm install @types/file-saver --save-dev

Then you create a method let say in your component:

some.component.ts

import { saveAs } from 'file-saver'; // Don't forget to import the file-saver
...    
saveLogFile(): void {
    saveAs(new Blob([log], { type: "text" }), 'data.log');
}

Where the [log] is the content of your log file, { type: "text" } this defines the type you wan't to save and 'data.log' defines how you wan't to save the file (filename.extension).

Upvotes: 7

Related Questions