<body>
and <head>
tag can be get in Angular ponent by injectingDOCUMENT
, like this:
import { DOCUMENT } from '@angular/mon';
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 ponent?
<body>
and <head>
tag can be get in Angular ponent by injectingDOCUMENT
, like this:
import { DOCUMENT } from '@angular/mon';
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 ponent?
- 3 And why exactly do you want that? – SiddAjmera Commented Dec 28, 2019 at 11:35
-
2
document.documentElement
? – evolutionxbox Commented Dec 28, 2019 at 11:35 -
@SiddAjmera sometimes, class or style may be used on
<html>
. But add these attributes directly on<html>
in the rootindex.html
will take effect globally. Setencapsulation: ViewEncapsulation.None
in specific ponent to ignore the shadow dom maybe a promise way, but it will affect all the "none encapusulation" ponents, which I don't want either. – funkid Commented Dec 28, 2019 at 11:44
1 Answer
Reset to default 10The documentElement
references the root element which will be <html>
in the browser.
https://developer.mozilla/en-US/docs/Web/API/Document/documentElement
@Component({..})
public class ExampleComponent {
public constructor(@Inject(DOCUMENT) doc: Document) {
console.log(doc.documentElement);
}
}