This episode dissects how Angular works behind the scenes: AOT and JIT compilation, change detection with zone.js, and the role of modules, components, directives, and services. You'll also learn about the component workflow, template syntax, data binding, and lifecycle hooks.

In episode 1 you learned about Angular's history and position. Now it's time to open the hood: how Angular works behind the scenes and what the main building blocks of its architecture are.
Episode 2 covers two things: how it works behind the scenes — AOT and JIT compilation, change detection, and zone.js — and the main building blocks — modules, components, directives, services, template syntax, data binding, dependency injection, and lifecycle hooks. This understanding will make the hands-on episodes that follow make much more sense.
Angular doesn't run templates directly. The HTML templates you write are compiled into efficient JavaScript code. There are two approaches:
Modern Angular uses AOT by default, even in development. Compiler options are configured via angularCompilerOptions in tsconfig.json.
{
"angularCompilerOptions": {
"strictTemplates": true,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true
}
}The strictTemplates config makes Angular check types inside HTML templates — errors like calling a property that doesn't exist get caught at build time instead of runtime. This is one reason Angular feels "strict" but safe.
Every time an event, HTTP response, or timer fires, Angular needs to know which part of the template changed. zone.js patches browser async APIs so Angular knows when a change happens, then runs change detection to update the view.
By default Angular checks every component from top to bottom. In episode 15 you'll learn the OnPush strategy to limit checking to only the components whose data actually changed.
These are the four main building blocks:
template -> kompilasi AOT -> kode efisien -> change detection saat eventA project created with ng new has a standard structure: src/app for application code, src/main.ts for bootstrap, angular.json for build configuration, and tsconfig*.json for TypeScript.
ng new arsitektur-app --style=scss --ssr=false
tree src/appNotice the root component app.component.ts, its template app.component.html, and app.config.ts, which holds global providers such as the router and HTTP client.
Angular templates are HTML plus special syntax. Interpolation displays values with double braces, property binding binds values to element properties, and event binding captures events from the user.
import { Component, signal } from '@angular/core';
@Component({
selector: 'app-hello',
standalone: true,
template: `
<input [value]="nama()" (input)="nama.set($any($event.target).value)" />
<p>Halo, {{ nama() }}</p>
<button (click)="reset()">Reset</button>
`,
})
export class HelloComponent {
readonly nama = signal('');
reset(): void {
this.nama.set('');
}
}Notice the binding patterns: [value] sends a value to an element, (input) receives an event, and {{ }} displays output. Dependency injection then supplies services to components via the constructor or the inject function — details covered in episode 6.
Angular components go through a lifecycle you can tap into with hooks:
ngOnChanges: called when an input changes.ngOnInit: called once after the first property binding.ngOnDestroy: called before the component is destroyed.import { Component, OnInit, OnDestroy } from '@angular/core';
@Component({
selector: 'app-lifecycle',
standalone: true,
template: `<p>Komponen lifecycle aktif</p>`,
})
export class LifecycleComponent implements OnInit, OnDestroy {
ngOnInit(): void {
console.log('Komponen diinisialisasi');
}
ngOnDestroy(): void {
console.log('Komponen dihancurkan');
}
}The ngOnDestroy hook is the right place to clean up subscriptions and timers so you don't leak memory.
Key takeaways:
In the next episode, episode 3, we'll build our first Angular project — creating an application with ng new, understanding the folder structure and key files, running the dev server with live reload, and setting up TypeScript, linting, and formatting. You'll see all these architecture concepts take shape in a real project.