Angular + .NET - Connect an Angular App to a .NET API
This is a quick post to show how to connect an Angular front-end app to a .NET back-end API.
The below example is a simple full-stack login application, the front-end client is built with Angular 14 and the back-end API is built with .NET 6.0.
Download and Start the example Angular App
Follow these steps to run the Angular 14 front-end app.
- Install Node.js and npm from https://nodejs.org.
- Download or clone the Angular project source code from https://github.com/cornflourblue/angular-14-jwt-authentication-example
- Install all required npm packages by running
npm ifrom the command line in the project root folder (where the package.json is located).
- Start the app by running
npm startfrom the command line in the project root folder, this will compile the Angular app and automatically launch it in the browser on the URL
Backend-less by default
The Angular app runs with a fake backend by default to enable it to run completely in the browser without a real API (backend-less), we'll switch to connect to the .NET API below once it's up and running.
For more info on the Angular App see Angular 14 - JWT Authentication Example & Tutorial.
Download and Start the example .NET API
Follow these steps to run the .NET 6.0 backend API.
- Install the .NET SDK from https://dotnet.microsoft.com/download.
- Download or clone the project source code from https://github.com/cornflourblue/dotnet-6-jwt-authentication-api
- Start the api by running
dotnet runfrom the command line in the project root folder (where the WebApi.csproj file is located), you should see the message
Now listening on: http://localhost:4000.
For more info on the .NET API see .NET 6.0 - JWT Authentication Tutorial with Example API.
Connect the Angular App to the .NET API
Back in the Angular app, remove or comment out the line below the comment
// provider used to create fake backend located in the
/src/app/app.module.ts file, then restart the Angular app and it should now be connected with the .NET API.
That's it! You now have a full stack Angular + .NET application running.
Need Some Angular Help?
Search fiverr to find help quickly from experienced Angular freelance developers.
Follow me for updates
When I'm not coding
My wife and I are attempting to ride motorcycles around Australia and vlog about it on YouTube.