Creating an Angular App: an overview

Angular is Google's framework for single-page apps. The browser loads one page and one app, and Angular builds and rebuilds the page from components, getting its data from APIs. It's written in TypeScript, and created and run with the Angular CLI.

Novice · Angular · Updated

After this lesson you can

  • Explain what Angular is, and how a single-page app differs from an MVC app

Key takeaways

  • An Angular app is a single-page app: the browser loads one page and the app once, and Angular builds every page in the browser from components.
  • An MVC app builds pages on the server and sends HTML; an Angular app gets its data from your Web API, as JSON.
  • MVC suits content sites that should load fast and be found by search engines; Angular suits apps people work in, such as dashboards and admin tools.
  • The Angular CLI, the ng command, does what dotnet does for C#: ng new creates an app, ng serve runs it, ng build gets it ready to publish.

In Calling APIs from JavaScript, a page fetched data and changed parts of itself without reloading. Build a whole app that way, with dozens of pages and hundreds of moving parts, and plain JavaScript gets hard to keep organized. That's the job of a front-end framework, and Angular is one of the big ones.

What Angular is

Angular is a framework for building web apps that run in the browser. It's made by Google, it's free, and it's written in TypeScript, which you just met. Big companies use it for large apps that teams work on for years, which is why it's a natural partner for ASP.NET Core.

A single-page app

Your MVC apps built every page on the server: each click asked the server for a new page of HTML.

An Angular app is a single-page app (SPA):

  1. The browser loads one HTML page and the app's JavaScript, once.
  2. Angular builds the page in the browser, from components: small pieces such as a header, a product card or a shopping cart.
  3. When the user clicks a link, Angular swaps components in and out, without asking the server for a new page.
  4. The data comes from your Web API, as JSON, with fetch-style requests.
ASP.NET Core MVC Angular with a Web API
Where pages are built On the server, by Razor views In the browser, by Angular components
What the server sends HTML pages The app once, then JSON
A click on a link A new page from the server Angular changes what's shown
Language for the page C# in Razor TypeScript

Neither is better for everything. MVC suits content sites and pages that should load fast and be found by search engines. Angular suits apps people work in: dashboards, admin tools, anything that feels like a desktop program.

The Angular CLI

You create, run, test and build an Angular app with the Angular CLI (command-line interface), the ng command. It plays the part dotnet plays for C#: ng new makes a project, ng serve runs it, ng generate adds parts to it, ng build gets it ready to publish.

The next lesson installs it and creates your first app.

Check yourself

1 question to try on the lesson page.

So what

An Angular app loads once and then builds every page itself, from components, with data from your API. It's the front end that turns your ASP.NET Core API into a full-stack app.

Key terms

Cheat sheets