Full answer
Browsers cannot read Angular templates. Somebody has to turn {{ marks() }} and (click)="add()" into JavaScript. There are two moments to do it.
AOT (ahead of time) is the default. During ng build and ng serve the compiler runs as part of TypeScript compilation. It reads each decorator, parses the template, and writes instructions into the class as static fields: ɵfac (how to create the class) and ɵcmp (the component definition with a template function). The output at the end of this answer is real compiler output for a tiny component.
Why AOT: the browser does not need to download or run the compiler (smaller and faster start-up), template errors become build errors, and templates are never parsed from strings at runtime, which also helps security.
Ivy is the name of the renderer and compiler design since Angular 9. A template function has two parts: a creation block (run once, creates DOM nodes) and an update block (run at each change detection, updates bindings). Because every component carries its own definition and refers to only the instructions it uses, bundlers can tree-shake unused framework features. Locality is also why each component compiles independently, which speeds up incremental builds.
Template type-checking. With strictTemplates: true (set by default in new projects) the compiler checks bindings against component types: a wrong input type, a missing property, or a missing import fails the build. It also reports things such as an arrow function inside a template, which the template syntax does not allow.
JIT (just in time) compiles in the browser at runtime. It is used in some test setups and in rare dynamic cases, not in production builds.
Build pipeline in current CLI: the application builder uses esbuild for bundling and Vite for the dev server, supports SSR and prerendering, produces hashed file names for caching, and enforces budgets from angular.json. Libraries are compiled in a partial format that the application's build links against its own Angular version.
import { Component, signal } from '@angular/core';
@Component({
selector: 'app-mark',
template: `
<p>Marks: {{ marks() }}</p>
<button (click)="add()">Add</button>
`,
})
export class MarkComponent {
readonly marks = signal(0);
add(): void {
this.marks.update((m) => m + 1);
}
}
/*
Compiler output (trimmed): the template becomes a function with a creation block
(rf & 1) and an update block (rf & 2).
static ɵcmp = i0.ɵɵdefineComponent({
type: MarkComponent,
selectors: [["app-mark"]],
decls: 4, vars: 1, consts: [[3, "click"]],
template: function MarkComponent_Template(rf, ctx) {
if (rf & 1) { // creation: runs once
i0.ɵɵdomElementStart(0, "p");
i0.ɵɵtext(1);
i0.ɵɵdomElementEnd();
i0.ɵɵdomElementStart(2, "button", 0);
i0.ɵɵdomListener("click", function MarkComponent_Template_button_click_2_listener() { return ctx.add(); });
i0.ɵɵtext(3, "Add");
i0.ɵɵdomElementEnd();
}
if (rf & 2) { // update: runs on each check
i0.ɵɵadvance();
i0.ɵɵtextInterpolate1("Marks: ", ctx.marks());
}
}
});
*/Angular 20.3 and TypeScript 5.8. The comment block at the end is the real output of `ngc` (Angular compiler CLI) for this component with `strictTemplates` enabled. Names and numbers in it can differ between Angular versions. Run `npx ngc -p tsconfig.json` with `outDir` set to see your own.
Key points
- AOT compiles templates at build time into `ɵfac` and `ɵcmp` static definitions.
- Ivy runs template functions with creation and update blocks and allows tree-shaking.
- `strictTemplates` turns template mistakes into build errors.
- JIT compiles in the browser and is not used for production builds.
Common mistakes
- Believing templates are interpreted as HTML strings at runtime.
- Turning off `strictTemplates` to silence errors instead of fixing the types.
- Thinking Ivy is a library you install. It is built into the compiler and runtime.
Follow-ups
- What is the difference between the creation and the update block of a template function?
- How are Angular libraries compiled so that they work with different app versions?
- How would you investigate a bundle that is too large?
Tips
- Show the creation versus update block. It proves you looked at the output.
- Link the answer to practical effects: errors at build time, smaller bundles, faster start-up.
- Avoid claiming specific percentages for speed or size. Say what you measured.
Evaluation rubric
- Explains AOT versus JIT and what the compiler emits.
- Understands Ivy's template function model and tree-shaking.
- Knows strict template checking and the modern builder.