Create the Angular Application
Create Project
- Create Project Folder named SuperHeroNG
- Download Node.js
- Open project forder in Visual Studio Code
- Set powershell policy with
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
- Download Angular CLI with
npm install -g @angular/cli
- Create new angular projekt skeleton with
ng new SuperHero.UI
in SuperHeroNG folder
- Add
components
,models
andservices
folders in src/app - Run angular with
ng serve -o
in SuperHero.UI folder
Add the Super Hero Model to the Client
Download Extensions
- Download
Angular Language Service
in Visual Studio Code
Super Hero Model
- SuperHero.UI/src/app/models/super-hero.ts
Generate an Angular Service
Service
- Move to app\services
- Create super-hero service with
ng g s super-hero --skip-tests
- SuperHero.UI/src/app/services/super-hero.service.ts
Component
-
Clear app/app.component.html
-
SuperHero.UI/src/app/app.component.ts
Run
- Run with
ng serve -o
Implement a Table to Show the Hero List
- SuperHero.UI/src/app/app.component.html
Create the .Net 6 Web API Project
- Create a ASP.NET CORE WEB API project named SuperHeroAPI on same folder with UI in Visual Studio
Add the Super Hero Model to the API
- SuperHeroAPI/SuperHero.cs
Add the Super Hero Controller
- SuperHeroAPI/Controller/SuperHeroController.cs
Call the Web API from the Angular 14 Client
-
Copy your Web API url and paste on your angular.
-
SuperHero.UI/src/environment/environment.ts
- SuperHero.UI/src/app/services/super-hero.service.ts
- SuperHero.UI/src/app/app.module.ts
- SuperHero.UI/src/app/components/app.component.ts
Enable CORS(Cross-Origin Resource Sharing)
- SuperHero.API/Program.cs
Add Entity Framework Core 6
-
Create Data folder in SuperHeroAPI
-
SuperHero.API/Data/DataContext.cs
- Download
Microsoft.EntityFrameworkCore.Design
andMicrosoft.EntityFrameworkCore.SqlServer
in Nuget Package manager
Add the Connection String for the SQL Server Database
- SuperHero.API/appsettings.json
Install the EF Core Tools
- Download Dotnet EntityCore Tools with
dotnet tool install --global dotnet-ef
and check withdotnet ef
Register the DataContext in the Program.cs
- SuperHero.API/Program.cs
Run the Initial Migration using Code-First Migration
- Migration data table with
dotnet ef migrations add Initial
- Update database with
dotnet ef database update
Get Super Heroes from the Database
- SuperHero.API/Controllers/SuperHeroController.cs
- Add a row in database
Implement Create, Update and Delete in the SuperHeroController
- SuperHero.API/Controllers/SuperHeroController.cs
Build a Edit-Hero Component with Angular
- Add a new component with
ng n c edit-hero --skip-tests
in app\components
- SuperHero.UI/src/app/components/edit-hero.component.ts
- SuperHero.UI/src/app.module.ts
- SuperHero.UI/src/app/components/edit-hero.component.ts
Add the Edit-Hero Form to the Parent Form
- SuperHero.UI/src/app/app.component.html
- SuperHero.UI/src/app/app.component.ts
Implement Web Service Calls on the client
- SuperHero.UI/src/app/services/super-hero.service.ts
Call the Service in the EditHero Component
- SuperHero.UI/src/app/components/edit-hero.component.ts
Update the Super Hero Table
- SuperHero.UI/src/app/app.component.ts
- SuperHero.UI/src/app/app.component.html