I am very new to Angular 2. I need to set up the meta tags like og: description and all from a component. I have no idea how to dynamically update the meta tags, also add new tags to the index.html from a particular component.
Please help.
PS: I read about title service, but that is to update the title only.
In Angular 4 you can easily update your web page title and meta tag information.
Import the predefined Meta Service in your component.
import { Meta, Title } from '@angular/platform-browser';
Inject the Service in Constructor.
constructor(private title: Title, private meta: Meta) {}
ngOnInit(){
this.title.setTitle('Angular Overview');
this.meta.updateTag({ name:'author',content:'angulartpoint.com'});
this.meta.updateTag({name:'keyword',content:'angular overview, features'});
this.meta.updateTag({name:'description',content:'It contains overview of angular application'});
}
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