I am able to set the tags dynamically in index.html with Meta concept in angular 4.but when I try to remove tags.its not removing ,How can I remove the tags whatever I have added before?
here is what I tried: setting the tags:
import {Meta ,MetaDefinition } from '@angular/platform-browser';
@Component({
selector: 'app-share-video',
templateUrl: './share-video.component.html',
})
export class ShareVideoComponent implements OnInit {
constructor(public metaServic:Meta){}
ngOnInit(){
const ogtitle: MetaDefinition = { name: 'og:title', content: 'Grace' };
const ogSitename: MetaDefinition = { name: 'og:site_name', content: 'My Favourite Albums'};
const ogUrl: MetaDefinition = { name: 'og:url', content: 'https://angular.io/docs/ts/latest/api/platform-browser/index/Meta-class.html'};
const ogdesc: MetaDefinition = { name: 'og:description', content: 'angular 4 share video description'};
this.metaService.addTag(ogtitle);
this.metaService.addTag(ogSitename);
this.metaService.addTag(ogUrl);
this.metaService.addTag(ogdesc);
}
ngOnDestroy() {
this.metaService.removeTag("property='og:title'");
this.metaService.removeTag("property='og:site_name'");
this.metaService.removeTag("property='og:url'");
this.metaService.removeTag("property='og:description'");
}
}
In the destroy method I am removing the tags, but these tags are not removing,how can I remove the tags? followed this:meta tags blog
The attribute selector that you are trying to use is name
, not property
.
You have to use
this.metaService.removeTag("name='og:title'");
this.metaService.removeTag("name='og:site_name'");
this.metaService.removeTag("name='og:url'");
this.metaService.removeTag("name='og:description'");
instead of
this.metaService.removeTag("property='og:title'");
this.metaService.removeTag("property='og:site_name'");
this.metaService.removeTag("property='og:url'");
this.metaService.removeTag("property='og:description'");
plnkr
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