SPA Using Angular 2, ASP.NET Core 1.1 And Entity Framework Core - Part One

Introduction

This is the first part of this series. In this series, we will create a SPA Application, using Angular 2, ASP.NET Core 1.1 and Entity Framework Core. Here, we use Angular 2 as UI for the Application, using ASP.NET Core MVC. We will perform Server side tasks and using Entity Framework Core, we will perform all the database level operations. In this series, we create an Employee Management system project. In this management system, we provide features to see the list of all employees, edit the existing employee, delete any particular employee and enter a new employee. Let’s go through the agenda of this series.

Agenda

  • Setup development environment for Angular 2.
  • Understand the structure of an Application.
  • Add Entity Framework in project.
  • Create new pages to see the Employee List and also for Insert, Update and Delete operations.
  • Perform Angular 2 routing.
  • Add Services.

Prerequisites

There some minimum configuration, which must be configured in your system before staring the work on this series.

  • Visual Studio 2015 Update 3 or Visual Studio 2017.
  • .NET Core 1.0.
  • Type Script 2.0.
  • js Version 6 or later.

After meeting all the above requirements, now we can setup SPA Application in some simple steps.

Getting started

The easiest way to get started is by using one of the project templates, which are made available. These plug into the standard dotnet new command and work on Windows, Mac in addition to Linux. To install the (Single Page Application)SPA templates, open the command prompt and run the command given below.

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

ASP.NET Core

The command given above takes some time and installs several templates for SPA like Angular, Knockout.js, React etc. The benefit of all these templates are that we don’t need to worry about the whole setup process.

To generate a new project, create an empty folder and name this project as EMS here. EMS is an abbreviation for Employee Management System. After creating an empty folder, now change the directory and go to this project. Now, run the command dotnet new angular.

ASP.NET Core

This command creates a template project for Angular 2 Application. Now, run “dotnet restore” commanpm nd. This command builds MSBuild file and restore all .NET dependencies.

ASP.NET Core

After installing all the .NET dependencies, now we install Node.js dependencies. Run “npm install” command. This command takes couples of minutes to install the required Node.js dependencies.

After creating the template project and installing all the required dependencies, now run “start EMS.csproj” command. This command will open your project in Visual Studio. Here, I am using Visual Studio 2017.

Now, press Ctrl + F5 and run the project.

ASP.NET Core

After running the project, if you get the above screen, then Congrats, as you successfully created Angular 2 Application. If you make any changes either in “.ts” files or “.html” file, you will get the live update as soon as you save the changes and don’t need to refresh the Browser.

ASP.NET Core

ASP.NET Core

Structure of the Application

After creating and running the Application successfully, let’s understand the structure of the project. Now, open Solution Explorer Window and you will find the project structure given below.

ASP.NET Core

Following are the major parts of our Application.

Dependencies

This section contains three types of the dependencies and npm dependencies are related to our Client Application. NuGet contains .NET Core level dependencies. SDK section contains system level dependencies.

launchSettings.json

This JSON file holds the project specific settings, which are associated with each debug profile, Visual Studio is configured to launch the Application, including any environment variables, which should be used. This file defines ApplicationURL, SSL port number and mode of authentication.

wwwroot

wwwroot section contains the “dist” folder. Here, dist folder contains the compiled code of our ClinetApp. All the code, which we write in template(.ts) or .html pages converts into a compiled code and save in a main-client.js file. This file contains the compiled form of all the components, Service and all other resources, which we create in our ClientApp folder.

ASP.NET Core

If you go to Index.cshtml view of Home controller, you fill find that we referenced the main-client.js file in Application startup process. 

  1. @{  
  2.     ViewData["Title"] = "Home Page";  
  3. }  
  4.   
  5. <app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>  
  6.   
  7. <script src="~/dist/vendor.js" asp-append-version="true"></script>  
  8. @section scripts {  
  9.     <script src="~/dist/main-client.js" asp-append-version="true"></script>  
  10. }   

ClientApp

This is client section of our project. Here, we write all Angular2 related code. Create component and Services. App folder contains components and app.module.ts file. The boot-client.ts file defines the root component selector.

ASP.NET Core

Controllers

In this section, we create MVC Controllers. In this project, we will use controller to get the data from the database.

Views

It defines V part of the MVC project, I think, we are already aware of Views.

Appsettings.json

Instead of web.config, all your settings are now located in appsettings.json. It contains all the configuration information in form of key-value pair. In this file, we define connection string and other Application level settings.

Packages.json

This file contains all Angular2 related dependencies.

Program.cs 

This is the entry point of the Application and is used to host the Application. In this file, we simply do the job of configuring & launching a host, using WebHostBuilder

Startup.cs

Startup.cs file works like a middleware and provide all the Services, which system requires to run.

tsconfig.cs

This file contains TypeScript configuration settings.

Webpack.config.js

Webpack works like a Package Manger and module bundler. It takes all the project modules with dependencies and generates the static assets, which represents these modules. Webpack and build and bundle CSS, JavaScript file, images all other static contents.

Configure Entity Framework

Now, we use Code First approach and create the database and tables. In our Application, we will use SQL Server for the database, so we need to install Entity Framework for SQL Server. To configure Entity Framework for SQL Server, we need to add SQL Server database provider.

Open Package Manager Console and run the command given below.

“Install-Package Microsoft.EntityFrameworkCore.SqlServer”

We will be using some Entity Framework tools to maintain the database. Thus, we need to install the tools packages as well. Hence, run the command given below to add all the required tools.

“Install-Package Microsoft.EntityFrameworkCore.Tools”

Create Entity classes

After adding the dependencies for Entity Framework, let’s create Employee and Project entity class. There will be a many to one relationship between Employee and Project entity. This means one employee can have only one project at a time but there can be more than one employees in a single project. Create a Model folder and add an Employee class in this folder.

Employee Entity

Add an Employee class in Models folder and replace the code of Employee class with the code given below. 

  1. using System.ComponentModel.DataAnnotations;  
  2. using System.ComponentModel.DataAnnotations.Schema;  
  3.   
  4. namespace EMS.Models  
  5. {  
  6.     public class Employee  
  7.     {  
  8.         [Key]  
  9.         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  10.         public int EmployeeId { get; set; }  
  11.         public string EmployeeName { get; set; }  
  12.         public string Designation { get; set; }  
  13.         public string Skills { get; set; }  
  14.         public int ProjectId { get; set; }  
  15.         public Project Project { get; set; }  
  16.     }  
  17. }   

In the code given above, EmployeeId property is a primary key for an Employee entity and it is also an identity type. The ProjectId is foreign key and corresponding navigation property is Project.

Project Entity

Now, add another class in Model folder and name this class Project, and replace the code of this class with the code given below. 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Threading.Tasks;  
  5.   
  6. namespace EMS.Model  
  7. {  
  8.     public class Project  
  9.     {  
  10.         public int ProjectId { get; set; }  
  11.         public string ProjectName { get; set; }  
  12.         public DateTime StartDate { get; set; }  
  13.         public DateTime EndDate { get; set; }  
  14.     }  
  15. }   

The ProjectId property is a primary key for this entity and other properties defines the information about the project.

Add DbContext Class:

The main class of any Entity Framework structure is DbCntext class. In this class, we define all the entities, which are used to create the table in the database. Now, add another class in Model folder and name it as EmployeeContext. This class will be derived from System.Data.Entity.DbContext class. Replace the code of this class with the code given below. 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.EntityFrameworkCore;  
  6. using EMS.Models;  
  7.   
  8. namespace EMS.Model  
  9. {  
  10.     public class EmployeeContext:DbContext     
  11.      {    
  12.         public EmployeeContext(DbContextOptions<EmployeeContext> options):base(options)    
  13.         {    
  14.     
  15.         }  
  16.         public DbSet<Employee> Employee { get; set; }  
  17.         public DbSet<Project> Project { get; set; }    
  18.     }    
  19. }   

In the code given above, we defined two Dbset properties for Employee and Project class. This property will create two tables in the database and name will be same, as defined in Dbset property.

Register Context with dependency Injection

After creating all entitities and dbContext classes, now we add a Service for Entity Framework such that any component requires this Service, which can be provided by constructor. In our controller constructor, we use this Service to get the context instance. Now, open startup.cs and add the code given below to ConfigureServices method.

services.AddDbContext<EmployeeContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

ASP.NET Core

In the code given above, we register a Service for DbContext. Here, DefaultConnection provides the connection string, which is defined in our appsettings.json. Now, open your appsettings.json” file and add the code given below. Replace the Server name with your SQL Server name. 

  1. {  
  2.   "ConnectionStrings": {  
  3.     "DefaultConnection""Server=*******;Database=Employee;Trusted_Connection=True;MultipleActiveResultSets=true"  
  4.   },  
  5.   "Logging": {  
  6.     "IncludeScopes"false,  
  7.     "LogLevel": {  
  8.       "Default""Debug",  
  9.       "System""Information",  
  10.       "Microsoft""Information"  
  11.     }  
  12.   }  
  13. }   

Add Migration and create a database

After configuring dbContext and entity classes now we add the migration and using the “Update-Database” command we will create our project database. First, we add the migration to open your “Package Manager Console”. Run “Add-Migration firstMigration” command. This command will add the Migrations folder in your project and first file in Migrations folder contains all the information on how to create your database.

ASP.NET Core

Now, we will run Update-Database command. This command takes codes, which are available in migration class and updates your database. In our case this command create an “Employee” database in SQL Server, which contains all the table and properties, which we defined earlier in our model classes.

Now, open your SQL Server and you will find that Employee database has been added.

ASP.NET Core

Add initial data

Now, our tables and database are ready. Let’s add some initial data into our tables.

Add data into Project Table 

  1. INSERT INTO dbo.Project    
  2. (    
  3.     ProjectName,    
  4.     StartDate,    
  5.      EndDate    
  6. )    
  7. VALUES( N'Lions',CAST('02/01/2017' as datetime),CAST('04/05/2017' AS datetime) ),(  N'OUP',CAST('08/09/2016' AS datetime),CAST('12/03/2017' AS datetime) ),    
  8. (   N'VMesh',CAST('12/04/2016' as date),CAST('04/01/2017' as date) )   


ASP.NET Core

AdddData into an Employee Table
 

  1. insert into Employee    
  2. (Designation,EmployeeName,ProjectId,Skills)    
  3. values('Developer','Raj Kumar',2,'C#,Asp.Net,MVC'),    
  4. ('Mobile Developer','Ankur Verma',3,'Java, Android Studio, Xamarin'),    
  5. ('Developer','Dheeraj Sharma',1,'C#,Asp.Net,MVC,AngularJS'),    
  6. ('Developer','Dhramveer',2,'C#,Asp.Net,MVC,AngularJS,Node.js'),    
  7. ('Mobile Developer','Shivam Kumar',1,'Java, Android Studio, Xamarin')   

ASP.NET Core

Now, our database and an Application setup is ready. Let’s start work with View section of an Application.

Show Employee List

Now, go to “app.modules.ts” file in “App” folder. In this file, you find that some default routes are defined like counter, home and fetch-data. We don’t need all these routes, so remove counter and fetch-data routes from routing table and also delete these components from components section. After all these changes, now go to navmenu.component.html file, remove Counter and Fetch Data items from the navmenu.component.html.

After all the changes given above, now our Application looks, as shown below.
ASP.NET Core

Now, we add some components, which are required in this project.

Employee Detail Component

Now, we add the details component and using this component, we will display the details of an employee.

ASP.NET Core

Right click on components folder, add a new folder and name this folder as details. This folder contains the content for the employee details component. Now, add a TypeScript file in this folder and name this file as details.component.ts and paste the code, as given below. 

  1. import { Component } from '@angular/core';  
  2.   
  3. @Component({  
  4.     selector: 'employee-detail',  
  5.     templateUrl: './details.component.html'  
  6. })  
  7. export class DetailsComponent {  
  8.       
  9. }   

Now, we need to add template file for this component fo which we are require to right click on details folder and an HTML file and name this file as details.component.html and paste the code given below.

  1. <h2>This is Detail Component</h2>   

Edit Employee Component

ASP.NET Core

In this project, we will provide the functionality to edit the details of any existing employee, for this we needs to add an “editEmployee” component. Thus, right click on components folder, add a new folder and name this folder as editEmployee. Now, add a TypeScript file and name this file as editEmployee.component.ts” and paste the code given below in it. 

  1. import { Component } from '@angular/core';  
  2.   
  3. @Component({  
  4.     selector: 'edit-employee',  
  5.     templateUrl: './editEmployee.component.html'  
  6. })  
  7. export class editEmployeeComponent {  
  8.   
  9. }   

Now, add HTML template file, name this file as editEmployee.component.html and paste the code given below.

  1. <h1>Edit Employee</h1>   

New Employee Component

ASP.NET Core
In this component, we write the code to enter a new entry for an employee. Right click on components folder and add newEmployee folder. Add a TypeScript file and name this file as newEmployee.component.ts and paste the code given below. 

  1. import { Component } from '@angular/core';  
  2.   
  3. @Component({  
  4.     selector: 'new-employee',  
  5.     templateUrl: './newEmployee.component.html'  
  6. })  
  7. export class newEmployeeComponent {  
  8.   
  9. }   

Now, add HTML template file and name this file as newEmployee.component.html and paste the code given below.

  1. <h1>This is New Employee component</h1>   

After adding all the required components for the project, now structure of ClinetApp section looks, as shown below.

ASP.NET Core

Add Routes for Components

After adding all the required components, now we need to perform the routing for these components. Open app.modules.ts file and paste the code given below into this file. 

  1. import { NgModule } from '@angular/core';  
  2. import { RouterModule } from '@angular/router';  
  3. import { UniversalModule } from 'angular2-universal';  
  4. import { AppComponent } from './components/app/app.component'  
  5. import { NavMenuComponent } from './components/navmenu/navmenu.component';  
  6. import { HomeComponent } from './components/home/home.component';  
  7. import { DetailsComponent } from './components/details/details.component';  
  8. import { newEmployeeComponent } from './components/newEmployee/newEmployee.component';  
  9. import { editEmployeeComponent } from './components/editEmployee/editEmployee.component';  
  10.   
  11.   
  12. @NgModule({  
  13.     bootstrap: [ AppComponent ],  
  14.     declarations: [  
  15.         AppComponent,  
  16.         NavMenuComponent,  
  17.         HomeComponent,  
  18.         DetailsComponent,  
  19.         newEmployeeComponent,  
  20.         editEmployeeComponent  
  21.     ],  
  22.     imports: [  
  23.         UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.  
  24.         RouterModule.forRoot([  
  25.             { path: '', redirectTo: 'home', pathMatch: 'full' },  
  26.             { path: 'home', component: HomeComponent },  
  27.             { path: 'details/:id', component: DetailsComponent },  
  28.             { path: 'new', component: newEmployeeComponent },  
  29.             { path: 'edit/:id', component: editEmployeeComponent },  
  30.             { path: '**', redirectTo: 'home' }  
  31.         ])  
  32.     ]  
  33. })  
  34. export class AppModule {  
  35. }   

In the code given above, we register all the components in declarations section and perform the routing for all these components.

Add new items in navmenu

Open navmenu.component.html file and paste the code given below in this file. 

  1. <div class='main-nav'>  
  2.     <div class='navbar navbar-inverse'>  
  3.         <div class='navbar-header'>  
  4.             <button type='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse'>  
  5.                 <span class='sr-only'>Toggle navigation</span>  
  6.                 <span class='icon-bar'></span>  
  7.                 <span class='icon-bar'></span>  
  8.                 <span class='icon-bar'></span>  
  9.             </button>  
  10.             <a class='navbar-brand' [routerLink]="['/home']">EMS</a>  
  11.         </div>  
  12.         <div class='clearfix'></div>  
  13.         <div class='navbar-collapse collapse'>  
  14.             <ul class='nav navbar-nav'>  
  15.                 <li [routerLinkActive]="['link-active']">  
  16.                     <a [routerLink]="['/home']">  
  17.                         <span class='glyphicon glyphicon-home'></span> Home  
  18.                     </a>  
  19.                 </li>  
  20.                 <li [routerLinkActive]="['link-active']">  
  21.                     <a [routerLink]="['/new']">  
  22.                         <span class='glyphicon glyphicon-user'></span> New Employee  
  23.                     </a>  
  24.                 </li>  
  25.             </ul>  
  26.         </div>  
  27.     </div>  
  28. </div>   

In the code given above, we add New Employee item nav menu. By clicking this menu item, we can open New Employee page and add a new entry for an employee.

So far, we have created all the components. Also, we performed the routing and added a new item in nav menu. Let’s check that all these changes are working or not. When you run this Application, the screen given below will open.

ASP.NET Core

When you click New Employee menu item, the screen given below will display.

ASP.NET Core

Show Employee List

ASP.NET Core

In our project’s home page, we will display the list of all the employees. We display the EmployeeName, Designation, Project information of an employee. First of all, we needs to create an API, using which we can get the list of all employee. Now, go to Controllers folder and a new API Controller, name this as EmployeeController and paste the code given below. 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.AspNetCore.Http;  
  6. using Microsoft.AspNetCore.Mvc;  
  7. using EMS.Model;  
  8. using EMS.ViewModel;  
  9. using Microsoft.EntityFrameworkCore;  
  10.   
  11. namespace EMS.Controllers  
  12. {  
  13.     [Produces("application/json")]  
  14.     [Route("api/Employee")]  
  15.     public class EmployeeController : Controller  
  16.     {  
  17.         private readonly EmployeeContext _context;  
  18.   
  19.         public EmployeeController(EmployeeContext context)  
  20.         {  
  21.             _context = context;  
  22.         }  
  23.         [HttpGet]  
  24.         public async Task<IActionResult> EmployeeList()  
  25.         {  
  26.             List<Employee_Project> ilIst = new List<Employee_Project>();  
  27.             var listData = await (from emp in _context.Employee  
  28.                                   join pro in _context.Project on emp.ProjectId equals pro.ProjectId  
  29.                                   select new  
  30.                                   {  
  31.                                       emp.EmployeeId,  
  32.                                       emp.EmployeeName,  
  33.                                       emp.Designation,  
  34.                                       pro.ProjectName  
  35.   
  36.                                   }  
  37.                           ).ToListAsync();  
  38.             listData.ForEach(x =>  
  39.             {  
  40.                 Employee_Project Obj = new Employee_Project();  
  41.                 Obj.EmployeeId = x.EmployeeId;  
  42.                 Obj.Designation = x.Designation;  
  43.                 Obj.EmployeeName = x.EmployeeName;  
  44.                 Obj.Project = x.ProjectName;  
  45.                 ilIst.Add(Obj);  
  46.             });  
  47.   
  48.             return Json(ilIst);  
  49.         }  
  50.     }  
  51. }   

In the lines of code given above, we create an asynchronous method. Asynchronous programming is a default mode of ASP.NET Core. Asynchronous programming provides a mechanism to write the code in non-blocking mode. We create an asynchronous EmployeeList method. In the first line of code, “List<Employee_Project> ilIst”, we create a list of “Employee_Project” ViewModel type. Here, “Employee_Project” is a ViewModel.

ViewModel in ASP.NET MVC is used to show only the required information., ViewModel is also used to show the data from two or more Models. Now, we add a ViewModel folder in the project. Add a new folder in the project and name it as ViewModels. After creating the viewModels folder, add a class in ViewModels folder. Right click on ViewModels folder and add a new class, name this class as Employee_Project. After creating the class, now paste the code given below in this class.  

  1. namespace EMS.ViewModel  
  2. {  
  3.     public class Employee_Project  
  4.     {  
  5.         public int EmployeeId { get; set; }  
  6.         public string EmployeeName { get; set; }  
  7.         public string Designation { get; set; }  
  8.         public string Project { get; set; }  
  9.     }  
  10. }   

Using LINQ query, we get EmployeeId, EmployeeName, Designation, ProjectName information about all the employees and add these values in iList object, using ForEach method. In the last line of code, we convert the ilist data into JSON format and return this JSON result to the required resource.

Now, our API is ready to return the employee list. Let’s check if it is working or not. Open your Browser, paste “http://localhost:54273/api/employee” URL and press enter. If you get the following JSON result, this means that our API is working perfectly.

ASP.NET Core

Now, our API is ready to return the employee list. Let’s use this API and display the employee information. We need a Service, which can use this API and get the result. Add a Service folder in an app section. After creating the folder, add a TypeScript file and name this file as services.ts and paste the code given below into this file. 

  1.  import { Injectable } from '@angular/core';  
  2. import { Http } from '@angular/http';  
  3.   
  4. @Injectable()  
  5. export class EmployeeServcies {  
  6.     constructor(private http: Http) {  
  7.          
  8.     }  
  9.     getEmployeeList() {  
  10.         return this.http.get('http://localhost:54273/api/employee');  
  11.     }  
  12. }   

In the code given above, we create an EmployeeServcies class and decorate this with @Injectable meta data. “@Injectbale meta data is used to define a class as a Service. In this Service class, we add getEmployeeList method. In this method, we are using GET method of HTTP class to perform HTTP GET request to the Server.

After creating the Service, now we need to register this Service in app.modules.ts file. Open your app.modules.ts file, import this Service and register this Service into providers. We are registering this Service in an app.modules.ts file, which means now this Service is a global Service. We can use this Service in any components and we don’t need to register this Service in each component.

ASP.NET Core

After creating and registering the Service, now we use this Service in our home component, so open home.component.ts file and paste fthe code given below. 

  1. import { Component } from '@angular/core';  
  2. import { EmployeeServcies } from '../../Services/services';  
  3. import { Response } from '@angular/http';  
  4. @Component({  
  5.     selector: 'home',  
  6.     templateUrl: './home.component.html'  
  7. })  
  8. export class HomeComponent {  
  9.     public EmployeeList = [];  
  10.     public constructor(private empService: EmployeeServcies) {  
  11.         this.empService.getEmployeeList()  
  12.             .subscribe(  
  13.             (data: Response) => (this.EmployeeList= data.json())  
  14.             );  
  15.   
  16.     }  
  17. }   

In the code given above, we create an instance(empService) of EmployeeServcies Service and use the getEmployeeList method of this Service to get the employee list. You can see that we are using a subscribe. Actually, an Angular 2 provides a new pattern to run asynchronous requests, which are knojwn as Observables, http is the successor to Angular 1's $http. Instead of returning a Promise, its http.get() method returns an Observable object. Using subscribe, method we can use the observable, the “subscribe” method tells the observable that you perform your task here is some one who listening and watching you. Perform the callback function when you return the result. In subscribe method, we get the data and assign the data into EmployeeList. Now, we use this list to display the employee list.

 Open home.component.html file and paste the code given below. 

  1. <div class="row">  
  2.     <div class="col-md-12">  
  3.         <h3>Employee List</h3>  
  4.         <br />  
  5.         <br />  
  6.         <br />  
  7.     </div>  
  8.       
  9. </div>  
  10. <div class="row">  
  11.     <div class="table-responsive">  
  12.         <table class="table">  
  13.             <thead>  
  14.                 <tr>  
  15.                     <th>  
  16.                         S.No.  
  17.                     </th>  
  18.                     <th>  
  19.                         EmployeeName  
  20.                     </th>  
  21.                     <th>  
  22.                         Designation  
  23.                     </th>  
  24.                     <th>  
  25.                         Project  
  26.                     </th>  
  27.                     <th>  
  28.                         Action  
  29.                     </th>  
  30.                 </tr>  
  31.             </thead>  
  32.             <tbody>  
  33.                   
  34.                 <tr *ngFor="let empData of EmployeeList; let i = index; trackBy: employeeId">  
  35.                     <td>  
  36.                         {{i+1}}  
  37.                     </td>  
  38.                     <td>  
  39.                         {{empData.employeeName}}  
  40.                     </td>  
  41.                     <td>  
  42.                        {{empData.designation}}  
  43.                     </td>  
  44.                     <td>  
  45.                        {{empData.project}}  
  46.                     </td>  
  47.                     <td>  
  48.   
  49.                         <a [routerLink]="['/details/',empData.employeeId]"  
  50.                            class="btn btn-primary">  
  51.                             Detail  
  52.                         </a>  
  53.                         <a [routerLink]="['/edit/',empData.employeeId]"  
  54.                            class="btn btn-success">  
  55.                             Edit  
  56.                         </a>  
  57.                         <a   
  58.                            class="btn btn-danger">  
  59.                             Delete  
  60.                         </a>  
  61.                     </td>  
  62.                 </tr>  
  63.                   
  64.         </table>  
  65.     </div>  
  66. </div>    

In the code given above, we perform ngFor on an EmployeeList and create a list of employees. We also add three anchor tags (Edit, Delete and Detail) for an each employee entry. We use the routerLink to link the anchor tag to the specific part of our app.

After making all the changes, save the project and refresh the Browser and you will get the result given below.

ASP.NET Core

Summary

This is the first part of SPA, using Angular 2, ASP.NET Core 1.1 and Entity Framework Core series. Today, we learned how to setup.NET Core project with Angular 2 and also understand the structure of the project. We also performed the setup for EF Core(Entity Framework) in this project. We created some component and performed the routing for these components. Create Service to get the data from Web API, using builtin http Service and display these data into a tabular format. In the next article, we will create some screens to add, delete or edit the employee information. We also provide the functionality of searching and sorting employee information.