A learning-focused Angular 19 app that demonstrates Angular lifecycle hooks, change detection patterns, signals, and RxJS-driven API flows using small standalone demo components backed by the REST Countries API.
- Angular 19
- TypeScript
- SCSS
- RxJS
- Node.js 18+ (latest LTS recommended)
- npm
npm installnpm startThe app runs at http://localhost:4200/.
npm start- start development servernpm run build- create production buildnpm run watch- build in watch mode (developmentconfig)npm test- run Karma unit tests
src/
app/
components/ # lifecycle hook and change detection demos
services/ # REST Countries API service
shared/ # reusable UI pieces (card/custom dropdown)
interfaces/ # shared app interfaces
- The app is bootstrapped with
bootstrapApplicationinsrc/main.ts. AppComponentrenders all demo components directly insrc/app/app.component.html.- Router is configured, but
src/app/app.routes.tscurrently exports an empty route array. ComponentsModuleaggregates and exports the standalone demo components used by the root component.- Top-level controls let you cycle
region,full name, andalpha codeinputs and toggle thengOnDestroydemo on and off.
CountryService uses the REST Countries API (https://restcountries.com/v3.1) and wraps several endpoint patterns, including:
/all/name/{name}/name/{name}?fullText=true/alpha/{code}/alpha?codes={codes}/region/{region}/subregion/{subregion}/currency/{currency}/lang/{language}/capital/{capital}/demonym/{demonym}/translation/{translation}/independent?status=true
Service methods normalize single-object and array responses into Country[] and return fallback empty arrays on HTTP errors.
From src/app/app.component.html:
understanding-ng-on-init- fetches countries by alpha codes duringngOnInitunderstanding-ng-on-changes- reacts to changingregionandalphaCodeinputs insidengOnChangesunderstanding-ng-do-check- manually diffs a search query inngDoCheckand runs full-text name lookupsunderstanding-ng-after-content-init- loads independent countries inngAfterContentInitunderstanding-ng-after-content-checked- triggers a one-time currency lookup inngAfterContentCheckedunderstanding-ng-after-view-init- usesViewChildreadiness inngAfterViewInitbefore loading language dataunderstanding-ng-after-view-checked- schedules a one-time subregion request fromngAfterViewCheckedunderstanding-ng-on-destroy- starts polling alternating endpoints and cleans up the subscription inngOnDestroyunderstanding-on-push-change-detection- demonstratesChangeDetectionStrategy.OnPushwith immutable updates andmarkForCheckunderstanding-signals-rest-integration- connects an Angular signal-driven region selector to REST dataunderstanding-lifecycle-logger-panel- logs hook execution order across the main lifecycle sequenceunderstanding-population-sort-demo- fetches a country list and reorders it by populationunderstanding-live-country-search-switchmap- debounced live search using RxJSswitchMapunderstanding-region-filter-dropdown- filters countries by region using a reusable dropdown
card- consistent visual wrapper used by the demoscustom-dropdown- reusable region selector used by the signals and filter demos
- Most demo components are standalone and grouped through
ComponentsModulefor convenience. AppComponentdrives several hook demos by rotating preset values for regions, country names, and alpha codes.UnderstandingLifecycleLoggerPanelComponentintentionally logs only the firstngDoCheck,ngAfterContentChecked, andngAfterViewCheckedcycles to keep the panel readable.UnderstandingNgOnDestroyComponentdemonstrates cleanup by unsubscribing from a polling stream when the component is removed from the DOM.
