Angular 6 and ASP.NET Core 2.0 Web API Example

Angular 6 and ASP.NET Core 2.0 Web API Example

Today, We want to share with you Angular 6 and ASP.NET Core 2.0 Web API Example.
In this post we will show you Single Page Application Using ASP.Net with angular 6, hear for How to Create an App with Angular 6 and ASP.NET Core 2.0 we will give you demo and example for implement.
In this post, we will learn about CRUD Operations With ASP.NET Core Using Angular 6 with an example.

Angular 6 Example

Angular Latest My Previous Post With Source code

  1. Angular 6 Folder Project Structure
  2. Angular 6 CLI Installation
  3. Angular 6 Module File
  4. Angular 6 Components
  5. Angular 6 Services
  6. Angular 6 Routing
  7. Angular 6 CSS
  8. Angular 6 Class Binding
  9. Angular 6 Animation
  10. Angular 6 Templating
  11. Angular 6 HTTP Client

As prerequisites, I shall need first of all the install the following List if they are not any system already installed:

As prerequisites,

  • 1.Visual Studio 2017
  • 2.Node.js as well as npm latest version
  • 3.ASP.NET Core 2.0

Phase for Making an App with Angular 6 & ASP.NET Core 2.0 using latest version Visual Studio 2017

Make a new ASP.NET Core Web Application.

Choose empty HTML template as well as trigger click OK.

You should be able to watch a solution with Latest frameworks ASP.NET Core 2.0 web application.

Right trigger click on the new project, add new directory as well as name it as Controllers.

Right trigger click on the Controllers directory, add new Item by right trigger clicking on Controllers directory as well as trigger click Add > Controller as well as name it datasController.

Choose API Controller as well as trigger click Add:

And then We shall watch datasController in the Controllers directory.

Excute Ctrl + F5 to run it, We shall watch “Welcome to!” on our browser.

onther way to navigate to main localhost:/api/userdatas, We shall still watch “Welcome to!” instead of datasController as We still need to configure Startup.cs.

Update Startup.cs as shown below source code:

public class Startup
  public void ConfigureServices(IServiceCollection services)
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    if (env.IsDevelopment())

And then when We refresh our browser with url localhost:/api/userdatas, We shall be able to watch the below:

And then it’s time to add Angular 6 app through Angular CLI to the same project, to do that, first open Developer Commas well as Prompt.

Then install Angular CLI globally using the below commas well as in the Developer Commas well as Prompt.

npm install -g @angular/cli

After installing Angular CLI globally, now navigate to Solution directory using commas well as cd.. as well as then:

run ng new MyFirstAngular6Core2App. Note that here name of the Angular App should be the same as the name of ASP.NET Core project, in my case, it is MyFirstAngular6Core2App.

Angular App shall be created in our solution as well as our solution shall look like below:

And then before running the Angular App, we need to configure few things – for that, first edit the .csproj file.

Modify the .csproj file, under the PropertyGroup, add

true ng build --aot 

as shown below, this will compile the TypeScript files using Angular CLI instead of Visual Studio.

And then edit angular.json file as well as set the outputPath to wwwroot. This setting will make sure that Angular CLI will copy the assets to wwwroot after the build (Ctrl + F5).

And then execute ng build in Developer Commas well as Prompt to build the angular App as well as hit Ctrl + F5 in Visual Studio to run the App as well as We should watch the below App in the browser.

To call datasController from Angular App, we need to modify app.module.ts, app.component.ts as well as app.component.html as follows:


import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }


//  Component
import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
 //  AppComponent
export class AppComponent {
  title = 'app';
  public userdatas: string[];
  constructor(private http: Http) {
    this.http.get('/api/userdatas').subscribe(result => {
      this.userdatas = result.json() as string[];
    }, error => console.error(error));


Welcome to {{ title }}!

some Loading...

{{ value }}

Run angular 6 ng build in Developer Comm as well as CMD Prompt.

Excute Ctrl + F5 in here latest version Visual Studio to run it as well as We shall watch the below some in our browser.

More Details of the Angular 6 Angular 6 Introduction Tutorial features of angular 6.0

Angular 6 Examples

There are the Angular 6 Step By Step Example and Learning AngularJS

We hope you get an idea about Angular 6 and ASP.NET Core 2.0 Web API Example
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.

Leave a Comment