I have an Angular 4 Universal application and I want to start using microdata in the format of JSON-LD.
It uses a script
tag with some content, e.g.:
<script type="application/ld+json">
{
"@context": "http://schema.org",
...
}
</script>
Since this data should change per view, I'm looking for a way to inject this data on route change in Angular 4. Currently, script tags are stripped from templates. When using a workaround with docuemnt.createElement
, this doesn't work on the server-side Angular Universal app.
How would I do this?
EDIT
I use Angular 4.x.x, which is now referred to as plain Angular.
I inject document
like so:
import { DOCUMENT } from '@angular/platform-browser';
class Test {
constructor(@Inject(DOCUMENT) private _document) {
}
public createScriptTag() {
this._document.createElement('script'); // doesn't work server-side
}
}