I want to build a component that processes user input from a textarea and serves it to the user as a (txt) file in Angular 9.
The form in app.component.html looks like this:
<form (ngSubmit)="onSubmit()" #myForm="ngForm">
<textarea name="myText" ngModel></textarea>
<input name="fileName" ngModel>
<button type="submit">Download</button>
</form>
My app.component.ts looks 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
}
}
How can I create a file with Angular based on the user input entered in the form and serve it to the user?