This is a small Angular SSR demo. The /products route renders product data from an injectable service on the server before the browser runs Angular JavaScript.
The same component is also available at /products-csr, but that route uses client-side rendering. This makes it easy to compare the raw HTML for SSR and CSR in one project.
src/app/products/products.service.ts: returns the demo product datasrc/app/products/products.ts: injects the service, stores data in signals, and derives summary values withcomputedsrc/app/products/products.html: renders the signal valuessrc/app/app.routes.server.ts: sets/productstoRenderMode.Serverand/products-csrtoRenderMode.Clientsrc/server.ts: allows locallocalhostrequests for the demo server
Build the browser and server bundles:
pnpm buildStart the SSR server:
pnpm serve:ssr:angular-ssr-service-demoOpen the page:
http://localhost:4000/products
Open the client-rendered comparison route:
http://localhost:4000/products-csr
In another terminal, request the raw HTML:
curl -s http://localhost:4000/productsThe response should already contain product HTML such as:
<h2>Mechanical keyboard</h2>
<h2>USB-C monitor</h2>
<h2>Wireless mouse</h2>It should also contain ng-server-context="ssr" and a server render timestamp.
Request the client-rendered route:
curl -s http://localhost:4000/products-csrThat response should contain the app shell and scripts, but not the product list HTML yet. The browser downloads JavaScript, hydrates/boots Angular, and then renders the component on the client.