Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 74 ยท Getting Started

Modern Angular vs AngularJS

AngularJS 1.x is retired. See how modern Angular differs (TypeScript, components, signals, no $scope or digest cycle) and which old tutorials advice to ignore.

Search for an Angular tutorial and you will find pages that start with ng-app, $scope and angular.module. That code is AngularJS, version 1.x, a framework released in 2010. The Angular you are learning here is a complete rewrite that first appeared in 2016 (people called it "Angular 2" back then) and has been rebuilt again in the years since. The two share a name and a few ideas, and almost nothing else.

AngularJS reached the end of its long-term support on December 31, 2021, so it no longer gets security fixes from the Angular team. Some companies still maintain AngularJS applications, and some third-party vendors sell extended support, but nobody should start a new project with it. If you maintain one, this lesson also gives you the mindset for moving off it.

The big differences at a glance

Topic AngularJS (1.x) Modern Angular
Language JavaScript (ES5 style) TypeScript
Building block Controllers, directives, $scope Components (classes with templates)
Change detection Digest cycle: dirty checking of watchers Signals, plus Zone.js or zoneless scheduling
Dependency injection String names ('$http') Typed classes and inject()
Templates Interpreted at runtime in the browser Compiled ahead of time at build
Structure ng-app attribute, global module bootstrapApplication() with standalone components
Tooling Script tags, or Grunt/Gulp Angular CLI and a modern bundler
Performance Slows down with many bindings Compiled output, fine-grained updates

Let's look at what these differences mean in code.

The same feature, two eras

Here is a small cart total in AngularJS. It is read-only code, shown so you can recognize the style:

HTML
<div ng-app="shop" ng-controller="CartController">
  <input type="number" ng-model="qty">
  <p>Total: {{ price * qty }}</p>
</div>
JavaScript
angular.module('shop', []).controller('CartController', function ($scope, $http) {
  $scope.price = 10;
  $scope.qty = 2;
  $http.get('/api/items').then(function (response) {
    $scope.items = response.data;
  });
});

Everything lives on a shared $scope object. The template can reach any property of it, and nothing checks that qty is spelled the same in both places. The controller's dependencies are found by the names of its parameters.

The modern version is a component. This is real Angular (read-only; the next lessons explain every part):

TypeScript
import { Component, computed, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';

@Component({
  selector: 'app-cart',
  imports: [FormsModule],
  template: `
    <input type="number" [(ngModel)]="qty" />
    <p>Total: {{ total() }}</p>
  `,
})
export class Cart {
  readonly price = 10;
  readonly qty = signal(2);
  readonly total = computed(() => this.price * this.qty());
}

The class owns its data, the template declares which other building blocks it uses (imports), and total is a derived value that Angular knows depends on qty. TypeScript checks the class, and Angular's compiler checks the template against it, so a typo like {{ totl() }} fails the build instead of silently showing nothing.

No more digest cycle

The most important conceptual change is how the screen finds out that data changed.

AngularJS used dirty checking. Every expression in a template registered a watcher. After any event (a click, a timer, an HTTP response) AngularJS ran a digest: it called every watcher, compared its value with the previous one, and if anything had changed it ran the digest again, until a full pass found no changes. That is simple to understand, but the cost grows with the number of watchers, and a watcher that changes data can force extra passes.

Modern Angular is moving to signals: values that know who reads them. When a signal changes, only the things that depend on it are marked for an update. The next diagram shows the contrast.

flowchart LR
  subgraph J["AngularJS digest"]
    direction TB
    E1["Event happens"] --> D1["Run every watcher"]
    D1 --> C1{"Anything changed?"}
    C1 -- yes --> D1
    C1 -- no --> U1["Update the page"]
  end
  subgraph S["Signals"]
    direction TB
    E2["signal.set()"] --> D2["Mark only dependents dirty"]
    D2 --> U2["Update affected parts of the page"]
  end

Dirty checking asks "did anything change?" about everything; signals already know what depends on what.

You will learn the details of signals in their own chapter later; for now the two stand-ins below let you feel the difference. They are not the real implementations, only models of the strategy.

Stand-in 1: a digest cycle

This model has a scope object and a list of watchers. digest() loops until a whole pass finds no changes, and counts every watcher check.

TypeScript A tiny dirty-checking digest

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

The watcher that updates total runs after the watcher that displays it, so the label is stale for one pass and a second pass is needed to fix it. Changing a single price costs 9 more watcher checks, including the title watcher whose value could not have changed.

Stand-in 2: a signal graph

Now the same data as signals. A computed caches its result and is only recomputed after one of the signals it read has changed. The model counts how often each function runs.

TypeScript A tiny signal and computed graph

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

After the price change only total and label run. title never read the price, so it is never touched. That is the whole idea behind signal-based updates, and it is why no one needs a global digest any more. (The real implementation also removes stale dependencies and supports effects.)

The two counts are not a benchmark. The point is the shape of the work: a digest checks everything on every pass, a signal graph touches only what depends on the change.

What to ignore in old tutorials

When a tutorial or Stack Overflow answer mentions any of these, it is about AngularJS and does not apply:

  • ng-app, ng-controller, ng-repeat, ng-model as attributes, and $scope, $rootScope, $watch, $digest, $apply.
  • angular.module(...), .controller(...), .factory(...) and .service(...) chains.
  • Two-way binding "everywhere by default". Modern Angular binds one way by default; two-way binding is an opt-in shorthand (lesson).
  • Filters in templates like {{ value | filter:...}} using the old API. Modern Angular has pipes, which look similar but are different.

Some older material is about Angular but from an earlier era. It still works in many cases but is no longer the recommended style: NgModule declarations, *ngIf and *ngFor (replaced by @if and @for), constructor injection (replaced in new code by inject()), and class members decorated with @Input() / @Output() (replaced by input() / output()). Version numbers in a tutorial's title or package.json tell you quickly which era you are reading.

AngularJS features and their modern replacements

If you inherit an AngularJS codebase, this map shows where each familiar piece went. Controllers, $scope and the digest cycle have no direct equivalent; they become components with signals.

AngularJS Modern Angular
ng-app, angular.module() bootstrapApplication() and app.config.ts
ng-controller, $scope A component class with signals
{{ expr }}, ng-bind, ng-bind-template Interpolation {{ expr }}
ng-bind-html [innerHTML] (sanitized automatically)
ng-model [(ngModel)], a form control or model()
ng-repeat @for (item of items; track item.id)
ng-if @if (...)
ng-show, ng-hide [hidden], [class.hidden] or @if
ng-switch @switch
ng-class, ng-style [class], [style] (or NgClass / NgStyle)
ng-class-even, ng-class-odd @for with let i = $index; let isEven = $even
ng-click, ng-keyup, ng-change, ... Event binding: (click), (keyup), (change)
ng-disabled, ng-readonly, ng-checked Property binding: [disabled], [readOnly], [checked]
ng-options @for over <option> elements
ng-include A child component, or ngTemplateOutlet
ng-cloak Not needed: templates are compiled before they reach the browser
ng-init A signal initialized in the class
ng-required, ng-maxlength Validators.required, Validators.maxLength(n)
Filters (currency, date, uppercase, limitTo, orderBy) Pipes (currency, date, uppercase, slice); sort in the class or a computed
$http HttpClient with interceptors
factory, service, provider One concept: an @Injectable class
$timeout, $evalAsync setTimeout, afterNextRender, signals
angular.forEach, isArray, copy, equals, toJson Array.forEach, Array.isArray, structuredClone, plain comparisons, JSON.stringify
$routeProvider, ui-router provideRouter(routes)

There is no orderBy pipe on purpose: a pipe that sorts a list on every check is slow and easy to misuse. Sort once in a computed signal and render the result.

A migration mindset

There is no button that turns an AngularJS app into an Angular app. The framework offers a hybrid approach (the ngUpgrade library) that lets both run in one page while you port one feature at a time. A realistic plan looks like this:

  1. Move the build to a modern tool and upgrade AngularJS to its last 1.8 release.
  2. Convert services to plain TypeScript classes with typed APIs.
  3. Rewrite leaf components first, running them next to old code in a hybrid app.
  4. Move routing last, then remove AngularJS entirely.

In most cases the work is a rewrite of the view layer with the business logic carried over, so the cheapest time to start is before the app grows.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which of these is a clear sign that a tutorial is about AngularJS, not modern Angular?

    $scope, ng-controller and angular.module belong to AngularJS 1.x. Modern Angular uses components and typed dependency injection.
  2. 2. How did AngularJS find out that data had changed?

    The digest cycle checked every watcher against its previous value and repeated until a full pass found no changes.
  3. 3. In the signal stand-in, why does the title computed not run again after the price changes?

    Dependencies are recorded when a computed runs. Title only read qty, so changing price does not invalidate it.
  4. 4. What is the recommended way to migrate a large AngularJS application?

    No automatic conversion exists. A hybrid setup lets old and new code coexist while you rewrite one piece at a time.

Summary

  • AngularJS (1.x) is a different, retired framework; support ended on December 31, 2021. Do not start new projects with it.
  • Modern Angular uses TypeScript, components, typed dependency injection, ahead-of-time compiled templates and the CLI.
  • AngularJS relied on a digest cycle that dirty-checks every watcher; modern Angular is moving to signals, which update only what depends on a change.
  • Ignore $scope, ng-controller, angular.module and similar in old tutorials. Treat NgModule, *ngIf, *ngFor and @Input() as older style.
  • Migrating means a gradual, feature-by-feature rewrite, not a conversion button.

Next: Setup and the Angular CLI