Hey everyone, I’m stuck trying to get my Angular app to talk to my Express backend API. I’ve got Postman working fine with JSON data, but I can’t figure out how to display it on my localhost or use the form to add new contacts.
Basically, I want my Angular app to have 4 input boxes for id, first name, last name, and email. Below that, I want to show my existing contacts from the API and any new ones added through the form. It would be awesome if clicking a contact opened a new page with more details.
Here’s a simplified version of what I’m working with:
To connect your Angular frontend with the Express backend, you’ll need to set up an HTTP client in Angular and create a service to handle API calls. Here’s a basic approach:
Install HttpClientModule in your Angular app.
Create a ContactService with methods for GET and POST requests.
Inject the service into your component and use it to fetch and add contacts.
Implement CORS on your Express server to allow requests from your Angular app.
In your component, you’d use the service like this:
hey there! have u tried using Angular’s HttpClient? it’s super handy for API calls. maybe u could make a ContactService that handles the backend communication? i’m curious, whats ur setup for handling CORS on the Express side? also, how r u planning to style ur contact list? sounds like an exciting project!
yo alex, sounds like ur on the right track! have u considered using httpinterceptors? they can be a game changer for handling errors n stuff. also, dont forget to sanitize ur inputs before sending em to the backend. oh and for that contact details page, u could use angular routing with route params. good luck man!