I have a simple Angular app written in ES2015 not TypeScript.
In AngularJS 1.x we could inject $document
to avoid using the document
browser global.
How can we do the same in Angular (the docs are all for TypeScript and, amazingly, none of the docs appear to show this fundamental requirement).
My main.js entry file (I'm using Webpack 2.2 also) is like this:
'use strict';
import 'reflect-metadata';
import 'zone.js';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';
let boot = document.addEventListener('DOMContentLoaded', () => {
platformBrowserDynamic().bootstrapModule(AppModule);
});
export { boot };
Currently this works, but it's using the global document
to add the DOMContentLoaded
event handler.
How can I inject some kind of Angular wrapper for the document
in Angular?
According to the official docs DOCUMENT
is an "injectible token", but I can't see any examples in using this. And I don't really have anything to inject it into.
I've tried importing it like this:
import {DOCUMENT} from '@angular/platform-browser';
But now DOCUMENT
is just a single object with a desc
property?