If you're working on your app-component.ts file
import { HttpClient } from '@angular/common/http';
export class AppComponent implements OnInit{
constructor(private http: HttpClient) { }
ngOnInit(): void {
this.http.post<string>("api/yourEndpoint", "Data to post, Type:<string>").subscribe(resonse=>console.log(resonse))
}
}
The ngOnInit function is triggered when the component is created. It doesn't require any visible content in app-component.html for it to run.
For more information, check out the official documentation
https://angular.io/guide/http#making-a-post-request