Sub topic 1
What Angular Is and When to Choose It
Angular is a web application framework from Google, written in TypeScript. You use it to build single-page applications (SPAs): apps that load once in the browser and then update the page with JavaScript, without a full reload for each screen. This chapter explains what Angular gives you, how it differs from view-only libraries, and how to decide whether it fits your project. Later chapters install the tools and build the app.
Prerequisites
This chapter assumes you are comfortable with:
- HTML and CSS fundamentals.
- Modern JavaScript: ES modules (
import/export), classes, and arrow functions. - Basic TypeScript: type annotations such as
name: string, and the decorator syntax@Something(). - Running commands in a terminal and installing packages with npm.
- Node.js, installed in an active or maintenance LTS release. You need it from the CLI chapter onward, not in this one.
You do not need any prior experience with Angular, AngularJS, React, or Vue. Where a comparison helps, this chapter explains the relevant parts of those tools.
The working model: a framework, not a library
A library is code that your code calls. A framework calls your code. With a framework, you write pieces that follow its rules, and it decides when to create, update, and destroy them. This is often called inversion of control.
React is the usual example of a view-only library. It renders UI from state, and that is its whole job. Routing, data fetching, forms, and build setup come from other packages that you choose and connect yourself. Meta-frameworks such as Next.js fill some of those gaps.
Angular takes the opposite approach. One team designs, versions, and releases the core pieces together:
| Concern | Angular's built-in answer | Typical view-library approach |
|---|---|---|
| Rendering UI | Components with HTML templates | Core library (JSX or templates) |
| Reactive state | Signals (`signal`, `computed`, `effect`) | Hooks, or a separate state library |
| Navigation between pages | `@angular/router` | Third-party router |
| Sharing logic and services | Built-in dependency injection | Context, modules, or a DI library |
| Forms and validation | `@angular/forms` (reactive and template-driven) | Third-party form library |
| HTTP calls | `HttpClient` in `@angular/common/http` | `fetch` or a third-party client |
| Build, serve, test, scaffold | Angular CLI (`ng`) | Vite or another bundler, configured per project |
| Server-side rendering | `@angular/ssr` | Meta-framework |
Because these packages ship together, they share one version number and one upgrade path. The ng update command can run automated code migrations when you move between major versions.
The building blocks at a glance
Each of these ideas gets its own chapter later. Here is how they fit together.
- Components are the units of UI. A component is a TypeScript class with a
@Componentdecorator that attaches a template (HTML) and optional styles. Modern Angular components are standalone: each one lists its own dependencies, and you do not need anNgModulewrapper. - Templates are HTML extended with Angular syntax.
{{ value }}shows data,[property]="expr"binds a DOM property,(event)="handler()"listens for events, and blocks such as@ifand@forhandle conditions and lists. - Signals hold reactive state. When a signal changes, Angular knows which parts of the view read it and updates them.
- Services hold logic that is not tied to one view, such as API calls or shared state. Angular's dependency injection (DI) system creates services and hands them to the components that ask for them, usually through the
inject()function. - The router maps URLs to components, so one page can act like many.
Here is a small preview of what Angular code looks like. You do not need to run it yet.
import { Component, signal } from '@angular/core';
@Component({
selector: 'app-hello',
template: `
<input (input)="name.set($any($event.target).value)" />
<p>Hello, {{ name() }}!</p>
`,
})
export class Hello {
name = signal('world');
}The class holds the state, the template describes the view, and Angular keeps them in sync.
Angular versus AngularJS
There are two different projects with similar names, and this is a common source of confusion.
- AngularJS (version 1.x, 2010) was a JavaScript framework built around scopes and two-way binding. Its long-term support ended on 31 December 2021.
- Angular (version 2 and later, 2016) is a full rewrite in TypeScript. It shares the name and some ideas, but the code is not compatible with AngularJS.
When you search for help, check that the answer is about Angular rather than AngularJS. Answers that mention $scope, ng-controller, or angular.module are about AngularJS.
How Angular has changed recently
Angular releases a major version about every six months. Each major version gets 18 months of support: six months of active development, then twelve months of long-term support for critical fixes. Recent releases changed the everyday developer experience a lot:
- Standalone components replaced
NgModuleas the default way to structure apps. - Signals became the main way to manage reactive state, along with signal-based
input()andoutput(). - Built-in control flow (
@if,@for,@switch) replaced structural directives in templates. - The build system moved to esbuild and Vite, which made builds and dev-server reloads much faster.
- Zoneless change detection, which drives updates from signals instead of patching browser APIs with Zone.js, became the default for new projects.
The overall effect is that modern Angular has less boilerplate than its reputation suggests.
When to choose Angular
Angular is a good fit when its structure saves you work.
- Large teams and long-lived apps. Every Angular project uses the same router, DI system, project layout, and CLI commands. A developer can move between Angular codebases and find things in the expected places.
- Enterprise and line-of-business apps. Apps with many forms, dashboards, and data tables benefit from the built-in forms package, DI, and strict typing.
- Teams that value TypeScript. Angular is written in TypeScript and type-checks templates, so many mistakes show up at build time.
- Predictable upgrades. Fixed release dates, a published support window, and
ng updatemigrations make maintenance easier to plan.
When to look elsewhere
Angular is not always the best tool.
- Mostly static content sites. Blogs and marketing pages are often better served by a static site generator or a content-focused framework such as Astro.
- Small widgets dropped into an existing page. A lighter library can be simpler to embed. Angular can do it (for example, with Angular Elements), but the setup is heavier.
- Teams already invested elsewhere. If your team has deep React or Vue experience and shared component libraries, switching has a real cost.
- Very short learning budgets. Angular has more concepts to learn up front (DI, decorators, the router, and RxJS in parts of the API) than a view-only library does.
Common misconceptions
| Misconception | Reality |
|---|---|
| "Angular requires NgModules." | Standalone components are the default. NgModules are optional and mostly appear in older code. |
| "Angular is the same as AngularJS." | They are separate frameworks. AngularJS is no longer supported. |
| "You must master RxJS before you can start." | Signals cover most component state. RxJS still appears in `HttpClient` and the router, but you can learn it gradually. |
| "Angular is only for huge apps." | It works for small apps too. Its advantages just grow with the size of the app and the team. |
| "Angular is slow." | Modern builds use esbuild, and signal-driven updates touch only the parts of the view that changed. |
Exercise
A team is building a five-year internal app with dozens of data-entry forms, role-based navigation, and several developers rotating in and out. Name three built-in Angular features that address these needs directly, and explain why a view-only library would need more setup.
Show answer
The forms package (@angular/forms) covers the data-entry forms and validation. The router, with route guards, covers role-based navigation. Dependency injection and the CLI's standard project structure help with shared services and with onboarding developers who rotate in. A view-only library such as React renders UI only, so the team would have to choose, connect, and keep upgrading a separate router, form library, and state or DI approach.
Exercise
You find a code sample that uses $scope and angular.module('app', []). Can you use it in an Angular project created with the current CLI? Why or why not?
Show answer
No. $scope and angular.module belong to AngularJS (1.x), a different framework that reached end of support on 31 December 2021. Modern Angular is a TypeScript rewrite that uses components, signals, and dependency injection, and its code is not compatible with AngularJS.
Exercise
List two signs that a tutorial uses an older Angular style, and give the modern equivalent of each.
Show answer
Any two of these: NgModule declarations, which are replaced by standalone components; ngIf and ngFor, which are replaced by the @if and @for blocks; @Input() and @Output() decorators, which are replaced by the input() and output() functions; constructor-only injection, which can be replaced by inject(); and component state kept in plain fields that rely on Zone.js, which is replaced by signals.