I am writing a form in Angular. Functionality is when I enter something in that form it posts that on back-end server and returns a response. I can see output in the console. I want to display that in HTML. I tried calling submitForm().
form: FormGroup;
constructor(
public fb: FormBuilder,
private http: HttpClient
) {
this.form = this.fb.group({
inputText: ['']
})
}
ngOnInit() {}
submitForm() {
var formData: any = new FormData();
formData.append("inputText", this.form.get('inputText').value)
this.http.post('http://127.0.0.1:5000/predictSentiment', formData).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
}
<div class="container sentiment" style="margin-top: 30px;">
<div class="row">
<div class="card col-md-6">
<div class="card-body">
<form [formGroup]="form" (ngSubmit)="submitForm()">
<div class="form-group">
<h2 class="card-title">Enter Your text</h2>
<textarea class="form-control" formControlName="name" cols="30" rows="10" placeholder="Enter text" style="width: 100%;"></textarea>
</div>
<div class="form-group">
<button class="btn btn-danger btn-block btn-lg">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="card col-md-6">
<div class="card-body">
<h2 class="card-title">Output:</h2>
<div *ngFor="let data of submitForm()">
{{data.response}}
</div>
</div>
</div>