Featured Article

Master AngularJS with .NET Core: The Ultimate Tutorial for Building Scalable Web Apps

Kenneth Jul 13, 2026

AngularJS is a highly popular JavaScript framework, widely used in web development due to its efficiency in creating dynamic and interactive user interfaces. In recent years, .NET Core has been gaining traction as a flexible, cross-platform development platform. Integrating AngularJS with .NET Core can amplify the strengths of both technologies, allowing for rapid development of robust, modern web applications. This tutorial walks you through the process of creating an AngularJS application using .NET Core.

HTML,CSS JAVASCRIPT cheatsheet
HTML,CSS JAVASCRIPT cheatsheet

Before we dive in, ensure you have installed the following prerequisites: .NET Core SDK (2.2 or later), Node.js (10.x or later), and Angular CLI (version compatible with your .NET Core version).

Dive Into Angular with This Comprehensive Beginner's Guide! 🚀
Dive Into Angular with This Comprehensive Beginner's Guide! 🚀

Setting up the AngularJS Project with .NET Core

.NET Core comes with Razor Pages, a simplified, model-view-controller (MVC) inspired web framework. Since AngularJS is a view framework, we'll structure our project around Razor Pages to utilize both technologies effectively.

an image of a diagram with the words angular development roadmap
an image of a diagram with the words angular development roadmap

To start, create a new ASP.NET Core Web App (Razor Pages) project using the .NET Core CLI. Navigate to your project directory in the terminal and run:

Install Angular CLI and initialize the Angular app

Angular
Angular

First, install Angular CLI globally using npm (Node Package Manager):

npm install -g @angular/cli

Then, initialize an Angular app inside the ' wwwroot' folder of your .NET Core project using Angular CLI:

ng new wwwroot --routing false

Update project configurations for AngularJS

angularjs .net core tutorial
angularjs .net core tutorial

Open your project's .csproj file and add the 'DistributeAngular' target to the 'ItemGroup' tag:

<Target Name="DistributeAngular">
  <Exec Command="ng build --prod" WorkingDirectory="wwwroot" />
</Target>

Add this line at the end of the file to call the 'DistributeAngular' target every time the application is built:

<Target Name="Build" />
<Target Name="AfterBuild">
  < targets='DistributeAngular' />
</Target>

Integrating AngularJS with Razor Pages

7 Free eBooks To Learn AngularJS
7 Free eBooks To Learn AngularJS

Now that our project is set up, let's integrate AngularJS with our Razor Pages.

In your Razor Pages, add a div element where the AngularJS content will be rendered:

#angular21 #angular #webdevelopment #frontend #javascript #typescript #learning | Husnain Khalid
#angular21 #angular #webdevelopment #frontend #javascript #typescript #learning | Husnain Khalid
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
Angular Best Practices to Build Web Applications
Angular Best Practices to Build Web Applications
angularjs .net core tutorial
angularjs .net core tutorial
difference between React and Angular
difference between React and Angular
#angular #webdevelopment #frontend #angular17 #angular18 #javascript #typescript #webperformance #devtools #pwa | Sonu Sindhu
#angular #webdevelopment #frontend #angular17 #angular18 #javascript #typescript #webperformance #devtools #pwa | Sonu Sindhu
Comparaison React vs Vue vs Angular. React vs Vue vs Angular comparison
Comparaison React vs Vue vs Angular. React vs Vue vs Angular comparison
#angular #signals #rxjs #webdevelopment | Sonu Sindhu | 12 comments
#angular #signals #rxjs #webdevelopment | Sonu Sindhu | 12 comments
#angular #frontenddevelopment #webperformance #softwareengineering #frontend #interviewprep | Naveenkumar S
#angular #frontenddevelopment #webperformance #softwareengineering #frontend #interviewprep | Naveenkumar S

<div id="appRoot"></div>

Add script references in _ViewStart.cshtml

Open '_ViewStart.cshtml' in your project's 'Pages' folder. At the end of the 'Head-section' tag, add this line for the Angular bundle:

<script src="~/wwwroot/app/app.js"></script>

Bootstrapping AngularJS in _ViewImports.cshtml

In '_ViewImports.cshtml', add these lines to bootstrap the AngularJS application:

@inject IHtmlHelper Html
@Html.AngularScript("appImported")

Now, replace '~/wwwroot/app/app.js' with the appropriate path to your app's entry point in the script tag added earlier, and restart your ASP.NET Core application.

Creating Your First AngularJS Controller

Let's create a basic AngularJS controller. In your Angular app (inside 'wwwroot/app'), create a new controller file like home.controller.js with this content:

angular.module('app').controller('homeCtrl', function ($scope) {
  $scope.message = 'Hello from AngularJS!';
});

Then, update your app.js to include this new controller. Finally, reflect your app's changes in the Razor Page by updating its content within the 'appRoot' div:

@inject AngularService Angular

@{Html.Angular("homeCtrl", "appRoot");}

You've now successfully integrated AngularJS with your .NET Core project. Continue to expand your AngularJS app within the 'wwwroot\app' folder, and update your Razor Pages to leverage this integration.

Hosting the Angular App

To serve the Angular app, update the file path in the Startup.cs file's ConfigureServices method:

services.AddSpaStaticFiles(configuration =>
{
    configuration.RootPath = "wwwroot/app";
});

In the Configure method, add the following lines before the app.UseHttpsRedirection(); line:

app.UseStaticFiles();
app.UseSpaStaticFiles();

Finally, change the route for the Angular app in the app.UseEndpoints line:

app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
    endpoints.MapSpaFallbackNavigation("./app");
});

Restart your ASP.NET Core application, and your Angular app should now be hosted on the root URL (e.g., 'http://localhost:5000').

Conclusion and Next Steps

By integrating AngularJS with .NET Core, you've expanded your toolset to tackle modern web development challenges. From here, you can build upon this foundation by exploring AngularJS concepts like directives, services, and routing, as well as leveraging .NET Core features like middleware, dependency injection, and C# async programming. Happy coding!