I have tried too many tricky ways,
such as Renderer2 or ɵDomAdapter,
the script tag is integrated well in the html,
but when loading the url with the structured-data tool of google,
the ld+json script is not rendered !
Is there a way to make google render the page after loading the component ?
2
Answers
There are a couple of ways to achieve this. The code below is the best solution I have come up with. This example will also work with Angular Universal.
I go into more detail in this blog post here https://coryrylan.com/blog/angular-seo-with-schema-and-json-ld
I also took this technique and wrapped it up into a npm package to make
it more reusable. https://github.com/coryrylan/ngx-json-ld
I used this variant in Angular 9 TypeScript
And then called it
<app-schema-org></app-schema-org>
For me the example above (https://stackoverflow.com/a/47299603/5155484) has no sense because it imports OnInit and implements OnChange and uses ngOnInit with a parameter for changes.
So here is my working fixed example.