I am attempting to develop a feature in Angular 9 that takes user input from a textarea, processes it, and then presents it back to the user as a downloadable (txt) file.
The structure of the form in app.component.html is as follows:
<form (ngSubmit)="onSubmit()" #myForm="ngForm">
<textarea name="myText" ngModel></textarea>
<input name="fileName" ngModel>
<button type="submit">Download</button>
</form>
In my app.component.ts file, the code appears like this:
import { Component, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild('myForm', {static: true}) myForm: NgForm;
onSubmit(){
// process this.myForm.value.myText
// serve file with this.myForm.value.fileName and myTextProcessed
}
}
Is there a way for me to generate a file using Angular based on the data entered by the user in the form and present it for download?