In Angular Universal I have an index.html file. At the top it has
<html lang="en">
I would like to change this based on the page I am on. maldonadoattorney.com/es/jailreleases would be
<html lang="es">
maldonadoattorney.com/jailreleases would be
<html lang="en">
Is there an accepted way of doing this? Have read other questions and DOCUMENT is deprecated, so am wary of using it.
I have my site map set up with hreflang tags, but would like the html lang tag to be correct. Currently, I'm taking the lang="en" tag out of my index.html.
You're right but DOCUMENT
from @angular/platform-browser
is deprecated in favor of DOCUMENT
from @angular/common
.
So you can use the following code:
import { DOCUMENT } from '@angular/common';
...
export class AppComponent implements OnInit {
constructor(@Inject(DOCUMENT) private document: Document) {}
ngOnInit() {
this.document.documentElement.lang = 'es';
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With