Issue
<body>
and <head>
tag can be get in Angular component by injectingDOCUMENT
, like this:
import { DOCUMENT } from '@angular/common';
import { Inject } from '@angular/core';
export class TestComponent {
constructor(
@Inject(DOCUMENT) private document: Document
)
// get <head>
// this.document.head
// get <body>
// this.document.body
}
But is it possible to get <html>
tag in Angular component?
Solution
The documentElement
references the root element which will be <html>
in the browser.
https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement
@Component({..})
public class ExampleComponent {
public constructor(@Inject(DOCUMENT) doc: Document) {
console.log(doc.documentElement);
}
}
Answered By - Reactgular
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.