Here we have also imported all our components and defined the route for our application as below
- <div class='main-nav'>
- <div class='navbar navbar-inverse'>
- <div class='navbar-header'>
- <button type='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse'>
- <span class='sr-only'>Toggle navigation</span>
- <span class='icon-bar'></span>
- <span class='icon-bar'></span>
- <span class='icon-bar'></span>
- </button>
- <a class='navbar-brand' [routerLink]="['/home']">ASPCoreWithAngular</a>
- </div>
- <div class='clearfix'></div>
- <div class='navbar-collapse collapse'>
- <ul class='nav navbar-nav'>
- <li [routerLinkActive]="['link-active']">
- <a [routerLink]="['/home']">
- <span class='glyphicon glyphicon-home'></span> Home
- </a>
- </li>
- <li [routerLinkActive]="['link-active']">
- <a [routerLink]="['/fetch-employee']">
- <span class='glyphicon glyphicon-th-list'></span> Fetch employee
- </a>
- </li>
- </ul>
- </div>
- </div>
- </div>
And that’s it. We have created our first ASP.NET Core application using Angular 5 and Entity Framework core database first approach.
Execution Demo
Press F5 to launch the application.
A web page will open as shown in the image below. Notice the URL showing route for our home component. And navigation menu on the left showing navigation link for Home and Fetch Employee pages.
Click on
Fetch Employee in the navigation menu. It will redirect to fetch employee component and displays all the employee data on the page.
Since we have not added any data, hence it is empty.
Click on
CreateNew to navigate to
/register-employee page. Add a new Employee record as shown in the image below. You can observe that the
City field is a dropdown list, containing all the city names that we have inserted into tblCities table.
If we miss the data in any field while creating employee record, we will get a required field validation error message
After inserting the data in all the fields, click on "Save" button. The new employee record will be created and you will be redirected to the
/fetch-employee page, displaying records of all the employees. Here, we can also see action methods Edit and Delete.
If we want to edit an existing employee record, then click Edit action link. It will open Edit page as below where we can change the employee data. Notice that we have passed employee id in URL parameter.
Here we have changed the City of employee Rahul from Hyderabad to Chennai. Click on "Save" to return to the fetch-employee page to see the updated changes as highlighted in the image below:
If we miss any fields while editing employee records, then Edit view will also throw required field validation error message as shown in the image below:
Now, we will perform Delete operation on an employee named Swati having Employee ID 2. Click on Delete action link which will open a JavaScript confirmation box asking for a confirmation to delete.
Once we click on Delete button the employee with name Swati will be removed from our record and you can see the updated list of employee as shown below.
Deploying the application
Open tsconfig.json file and add the following line:
"strictNullChecks”: false
Refer to the image below:
When we publish the application , Visual Studio will run “node node_modules/webpack/bin/webpack.js –config webpack.config.vendor.js –env.prod” command. Adding the above mentioned line in tsconfig.json file will ensure that this command will not strictly check for any null values in our application.
Please note that if you are not publishing this application then you do not need to add “strictNullChecks”: false in your tsconfig.json file.
Conclusion
We have successfully created an ASP.NET Core application using Angular 5 and Entity Framework core database first approach with the help of Visual Studio 2017 and SQL Server 2012. We have used Angular forms to get data from the user and also bind the dropdown list to database table using Entity framework.
You can also read my other articles
here.
Please post your valuable feedbacks in the comments section below.