In an Angular component, the <body>
and <head>
tags can be accessed by injecting DOCUMENT
as shown below:
import { DOCUMENT } from '@angular/common';
import { Inject } from '@angular/core';
export class TestComponent {
constructor(
@Inject(DOCUMENT) private document: Document
)
// To get <head>
// this.document.head
// To get <body>
// this.document.body
}
But the question arises: Is it possible to access the <html>
tag in an Angular component?