How the App Boots and Renders
-
Static Host Page
src/index.htmlprovides the bare HTML page with<app-root></app-root>. This is the DOM node Angular will attach to. -
Entry Script (
main.ts)
-import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));bootstrapApplicationspins up Angular using the standalone API. -AppComponentis declared as the root component. -appConfigregisters global providers, including routing and zone-based change detection. -
App Configuration (
app.config.ts)
- Ensures Angular listens for browser events and runs change detection. - Registers the router with the route definition that pointsexport const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), ], };/to the sandbox component. -
Root Component (
app.component.ts)
- When bootstrapped, Angular renders@Component({ selector: 'app-root', standalone: true, imports: [RouterOutlet], template: `<router-outlet />`, }) export class AppComponent {}<router-outlet>into<app-root>. - The router then loads theSandboxComponentfor the default route. -
Sandbox Route (
app.routes.ts)
- Navigating toexport const routes: Routes = [ { path: '', component: SandboxComponent }, ];/instantiatesSandboxComponentand inserts its template into the page.
How the “Show Modal” Button Works
-
Sandbox State
-export class SandboxComponent { modalOpen = signal(false); toggleModal(state: boolean): void { this.modalOpen.set(state); } }signal(false)stores modal visibility. Signals are reactive primitives in Angular 16+. -toggleModal(true)opens the modal;toggleModal(false)closes it. -
Button Interaction
- When the user clicks, Angular executes<ui-button (click)="toggleModal(true)">Show Modal</ui-button>toggleModal(true). - The signal updates totrue, markingSandboxComponentfor change detection. -
Modal Template Binding
- The custom<ui-modal [open]="modalOpen()" title="Component Library" (requestClose)="toggleModal(false)" > <!-- modal body --> </ui-modal>ui-modalcomponent receives the signal value via[open]="modalOpen()". - Angular re-evaluates the template after the signal changes and passestrueto the modal. -
Modal Component Logic
- When@Component({ selector: 'ui-modal', standalone: true, imports: [CommonModule], template: ` <section class="backdrop" *ngIf="open" (click)="onBackdropClick($event)"> <article class="modal" role="dialog" [attr.aria-modal]="true" [attr.aria-label]="title"> <header class="modal__header"> <h2>{{ title }}</h2> <button type="button" (click)="requestClose.emit()">×</button> </header> <section class="modal__body"> <ng-content></ng-content> </section> <footer class="modal__footer"> <ng-content select="[modal-actions]"></ng-content> </footer> </article> </section> `, }) export class ModalComponent { @Input() open = false; @Output() requestClose = new EventEmitter<void>(); onBackdropClick(event: MouseEvent): void { if (event.target === event.currentTarget) { this.requestClose.emit(); } } }[open]istrue, the*ngIfrenders the modal markup. - Clicking the close button or backdrop emitsrequestClose, which callstoggleModal(false)in the sandbox. -
Angular Change Detection Cycle
- The button click runs inside Angular’s zone; change detection runs automatically. - The signal change updates the view, showing the modal instantly without manual DOM manipulation.
Try It Yourself
cd examples/week01-02
npm install
npm start
- Navigate to http://localhost:4200 and click Show Modal to see the signal-driven UI.
- Modify text or styling in ui-modal or ui-button and watch the updates live via Angular CLI’s HMR.