Search code examples
angularangular-renderer

Append children to document.body angular way


I have written code like below

this._renderer.appendChild(document.body, form);

This works fine. But i am directly accessing document.body. Is there a angular 2/4 way of access document.body?


Solution

  • You can inject via DOCUMENT injection token. This will give you the document object in Angular way (as you have said).

    constructor(@Inject(DOCUMENT) private document: Document)