Injecting the document object in an Angular component is quite straightforward. All you need to do is import the DOCUMENT DI token from @angular/common.
  1. import { DOCUMENT } from '@angular/common';
And insert it using in @Inject decorator.
  1. import { Component, Inject } from '@angular/core';
  2. import { DOCUMENT } from '@angular/common';
  3. @Component({.....})
  4. export class OrderComponent {
  5. constructor (
  6. @Inject(DOCUMENT) private document: Document
  7. ) {}
  8. }
You could do the same for a service
  1. import { Inject, Injectable } from '@angular/core';
  2. import { DOCUMENT } from '@angular/common';
  3. @Injectable({.....})
  4. export class OrderService {
  5. constructor (
  6. @Inject(DOCUMENT) private document: Document
  7. ) {}
  8. }