Angular and Domino: A Powerful Combo for Server-Side Rendering.

If you are using Angular and need to access DOM with SSR, then use the domino package.
Domino provides support for the DOM API and also CSS for querySelector(), querySelectorAll(), and matches().
Install the domino package from your terminal.
npm install domino --saveAdd angular universal in your app. ng add @nguniversal/express-engine Edit the server.ts file and add the following lines. To configure it, create a "document" object and a "window" as global.
const domino = require('domino');
const fs = require('fs');
const path = require('path');
// Use the browser index.html as a template for the mock window
const template = fs
.readFileSync(path.join(join(process.cwd(), 'dist/yourprojectname/browser'), 'index.html'))
.toString();
// Shim for the global window and document objects.
const window = domino.createWindow(template);
global['window'] = window;
global['document'] = window.document;If you want to copy and paste, please change the project name.
Keep in mind that change for server-side render, the build command is built:ssr and needs to publish the browser directory.
npm run build:ssr
dist/yourprojectname/browserRelated Articles
Angular Forms: Choosing Between Reactive and Template Driven Forms
When we start to build an application in Angular and need to create forms, we must pick one of the two flavors: "Reactive" or "Template Forms". For beginners, Template Forms are natural and appear less complex for new joiners, but some developers may...
Angular's 'exportAs' Feature: A Practical Guide to Sharing Component State
In Angular when we build components with public properties or the state to share with others, some options come into our heads to solve it: Emit an event using the new value of the component state. Inject service with Subject to share the state. Inj...
Real Software. Real Lessons.
I share the lessons I learned the hard way, so you can either avoid them or be ready when they happen.
Join 13,800+ developers and readers.
No spam ever. Unsubscribe at any time.