EDIT: as stated in the comments, this solution is a hacker solution and should be used with caution.
You can enter some other types and functions of "ɵgetDOM" and "ɵDomAdapter" to get a link to dom. Sorry for calling it "some" service and function, because I don’t have a clue why they are called that. I just looked at the source code and how the angular command does this with MetaService.
import { Inject } from '@angular/core'; import { Meta, Title } from '@angular/platform-browser'; import { ɵgetDOM, ɵDomAdapter, DOCUMENT } from '@angular/platform-browser'; @Injectable() export class SeoService { private dom: ɵDomAdapter; constructor(@Inject(DOCUMENT) private document: any, private titleService: Title, private metaService: Meta) { this.dom = ɵgetDOM(); let scriptEl = this.dom.createElement('script');
I tested this and used it in production.
source share