Support for AngularJS ended in December 2021. Applications written with it still run in thousands of companies, and every year the list of reasons to move grows: security fixes that will not come, libraries that are gone, developers who do not want to touch it. There is no upgrade from AngularJS to Angular. They share a name and little else. The application is rewritten, screen by screen.
A rewrite of a user interface is judged by people who have used the old one for years and notice everything. This case rewrites a small order desk and checks the result with tests that act like those people. The code is on GitHub: chudovo/application-modernization, case 12.
At a glance
| Before | After | |
|---|---|---|
| Framework | AngularJS 1.8.3 | Angular 22 |
| Language, build | JavaScript, no build step | TypeScript, Angular CLI |
| Structure | controllers and templates | standalone components with signals |
| Lists | filter and orderBy in the template | code in the component |
| Routing | addresses like /#!/orders/3 | addresses like /orders/3 |
| Browser tests passing | 12 of 12 | 12 of 12, after 2 of 12 in the first port |
Step 1: tests that only know the page
Twelve tests drive a real browser through Playwright. They click, type, read what is on the page, and look at what reached the server. They know nothing about either framework, so the same file runs against the AngularJS application and the Angular one. Both talk to the same small backend.
test('search looks at every field and ignores letter case', async ({ page }) => {
await page.goto('/');
await expect(column(page, 'customer')).toHaveCount(5);
await page.locator('[data-test="search"]').fill('BERLIN'); // a city, typed in capitals
await expect(column(page, 'customer')).toHaveText(['Anna Schmidt', 'Zoë Ärmel']);
await expect(page.locator('[data-test="count"]')).toHaveText('2 orders');
});
test('a bookmark from the old application still opens the order', async ({ page }) => {
await page.goto('/#!/orders/3');
await expect(page.locator('[data-test="title"]')).toHaveText('Order 3: Zoë Ärmel');
});
The tests were first run against the old application, and two of my expectations turned out to be wrong. The old application defines the truth, so the tests were corrected, not the application.
Step 2: the first port
In AngularJS a list with search and sorting is one line of template:
<!-- AngularJS: searching and sorting happen in the template, in one line -->
<tr ng-repeat="order in vm.orders | filter: vm.search | orderBy: vm.sort : vm.reverse">
<td><a ng-href="#!/orders/{{order.id}}">{{order.customer}}</a></td>
<td>{{order.total | currency}}</td>
<td>{{order.placed | date: 'mediumDate' : 'UTC'}}</td>
</tr>
Angular has no filter and no orderBy pipe, deliberately. Whoever ports the screen writes that logic in the component, and writes what they believe it did:
// The first port: what a developer writes who looks at the screen, not at what the two filters did
readonly visible = computed(() => {
const term = this.search().toLowerCase();
const column = this.sort();
const found = this.orders().filter((order) => order.customer.toLowerCase().includes(term));
found.sort((a, b) => (a[column]! > b[column]! ? 1 : -1));
return this.reverse() ? found.reverse() : found;
});
That code is reasonable. It compiles, and the screen looks right.
| Tests passing | |
|---|---|
| AngularJS application | 12 of 12 |
| First Angular port | 2 of 12 |
| First port, old addresses handled | 6 of 12 |
| Finished version | 12 of 12 |
Old addresses lead somewhere else
AngularJS addresses look like /#!/orders/3. They are in bookmarks, in e-mails to customers, in wiki pages. The Angular router uses /orders/3 and treats everything after the hash as a fragment, so an old address opens the list of orders. No error page, no message. Five of the twelve tests open an order through such an address, and all five failed.
// main.ts. Addresses of the AngularJS application looked like /#!/orders/3, and they are in bookmarks, e-mails
// and wikis. The Angular router uses /orders/3. Without this line an old address opens the list, silently.
if (location.hash.startsWith('#!/')) history.replaceState(null, '', location.hash.slice(2));
bootstrapApplication(App, appConfig).catch((err) => console.error(err));
What the template did without saying
| What the user does | AngularJS | First Angular port |
|---|---|---|
| Types BERLIN into the search box | finds the two orders from Berlin | finds nothing: only the customer name was searched |
| Clicks the Customer column | Anna, bernd, carla, Zoë, Émile | Anna, Zoë, bernd, carla, Émile |
| Clicks the Total column | the order without a total comes last | it comes first |
| Chooses All in the status filter | GET /api/orders | GET /api/orders?status= |
| Opens an order | Feb 11, 2026 8:00:00 AM | Feb 11, 2026, 8:00:00 AM |
The first three rows come from the two filters. With a text, the AngularJS filter matches an item if any of its values contains the text, ignoring letter case. Users have been searching by city and by status for years without anyone having designed that. And orderBy ignores letter case and puts empty values last. A plain sort does neither.
The finished version keeps that behaviour in one file, written out:
/** The AngularJS "filter" with a text: an item matches if any of its values contains the text, ignoring case. */
export function matchesAnyField(item: object, text: string): boolean {
const term = text.toLowerCase();
return Object.values(item).some((value) => value !== null && value !== undefined && String(value).toLowerCase().includes(term));
}
/** The comparison "orderBy" used: strings lower-cased, character by character, and empty values last. */
export function compareLikeOrderBy(a: unknown, b: unknown): number {
const missingA = a === null || a === undefined;
const missingB = b === null || b === undefined;
if (missingA || missingB) return missingA === missingB ? 0 : missingA ? 1 : -1;
const x = typeof a === 'string' ? a.toLowerCase() : a;
const y = typeof b === 'string' ? b.toLowerCase() : b;
return x === y ? 0 : (x as string | number) < (y as string | number) ? -1 : 1;
}
Whether É should come after Z is debatable. But a list that changes its order on the day of the release produces support calls, and the decision to sort differently should be made by someone, not by a rewrite.
A parameter that used to disappear
// AngularJS: an empty status is passed as null, and $http leaves it out of the address.
$http.get('api/orders', { params: { status: vm.status || null } }); // GET /api/orders
// Angular, first port: TypeScript does not allow null here, so the empty string goes in.
this.http.get<Order[]>('api/orders', { params: { status } }); // GET /api/orders?status=
// Angular, finished:
this.http.get<Order[]>('api/orders', { params: status ? { status } : {} }); // GET /api/orders
The backend in this case treats an empty status as no filter, so the list looked the same and only the test that reads the server’s log noticed. Another backend may answer the literal question, orders whose status is empty, and return nothing.
What translated without surprises
- currency and short date formatting
- sanitising of HTML in a note: formatting and links stay, scripts and event handlers go, in both frameworks
- form validation: required, minimum, maximum, the Save button disabled while the form is invalid
- numbers from a number input reach the server as numbers
- the XSRF token: both frameworks read the cookie and send the header without any code
- the wording of counts: no orders, one order, five orders
That is the larger part of the application, and it is the part people worry about. The failures were all in behaviour that nobody knew the old framework was providing.
What is verified, and what is not
| Check | Result |
|---|---|
| 12 browser tests against the AngularJS application, Chromium | 12 / 12 |
| The same 12 against the Angular application, Chromium | 12 / 12 |
- One browser. Chromium only.
- Not how it looks. The tests read texts, attributes and requests. No screenshots are compared.
- Not a gradual migration. Large AngularJS applications are usually moved piece by piece, with both frameworks in one page for months. This case rewrites a small application in one go.
- Not the hard parts of a big application: custom directives, chains of watchers, events on the root scope, third-party AngularJS widgets. That is where the effort goes.
One choice in the test setup is deliberate. The test browser has a German locale and the Berlin time zone, while the application formats in US English and UTC. Neither application takes its formats from the browser, and a port that starts to would be caught.
Run it yourself
You need Node 22:
cd before && npm ci
cd ../after && npm ci && npx ng build
cd ../e2e && npm ci && npx playwright install chromium && npx playwright test
When this path fits
For an AngularJS application there is no alternative to a rewrite, only a choice of how: all at once for a small application, piece by piece for a large one, and into Angular or into another framework. Whatever the route, write the browser tests against the old application first. They are the only specification it has. Where a front-end rewrite sits in a larger plan is covered in the application modernization strategy guide. A related case ports a server-rendered application: ASP.NET MVC 5 to ASP.NET Core MVC.
If you need a team for a rewrite like this, see our comparison of modernization vendors.