Posted inTechnology / AngularJS / ASP.NET

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 Read more…..

  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 Pakainfo.com!” on our browser.

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

Update Startup.cs as shown below source code:

public class Startup
{
	//pakainfo.com 
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddMvc();
  }
	//pakainfo.com 
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
    if (env.IsDevelopment())
    {
      app.UseDeveloperExceptionPage();
    }
 
    app.UseMvc();
 
    app.UseDefaultFiles();
    app.UseStaticFiles();
  }
}

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:

app.module.ts

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

app.component.ts

//pakainfo.com  Component
import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';
 
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
 //pakainfo.com  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));
  }
 
}

app.component.html



Welcome to {{ title }}!

some Loading...

Values
{{ 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!.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype