Article

Working around browsers' APIs

AOAnonymous One· Dec 4, 20221 min read
  • #Angular
  • #SSR
  • #Angular Universal

Working around browsers' APIs

While using Angular SSR, the Universal application does not execute in the browser, and some of the browser APIs and capabilities might be missing on the server.

For example, server-side applications can't reference browser-only global objects such as window, document, navigator, or location.

Angular provides some injectable abstractions over these objects, such as Location or DOCUMENT.

Using DOCUMENT provided Angular injectable abstraction:

import { DOCUMENT } from "@angular/common";

constructor(@Inject(DOCUMENT) private document: Document) {
    this.document.location.reload();
}

References:

0 Comments

Sign in to join the conversation.

Search

Jump to a page, story or project