How To Inject Document In Angular Component Or Service

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.   
  4. @Component({.....})  
  5. export class OrderComponent {  
  6.     constructor (  
  7.         @Inject(DOCUMENT) private document: Document  
  8.     ) {}  
  9. }
You could do the same for a service
  1. import { Inject, Injectable } from '@angular/core';    
  2. import { DOCUMENT } from '@angular/common';    
  3.     
  4. @Injectable({.....})    
  5. export class OrderService {    
  6.     constructor (  
  7.         @Inject(DOCUMENT) private document: Document    
  8.     ) {}    
  9. }