Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the tags using Meta in angular 4

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

like image 283
Sathish Kotha Avatar asked Jun 06 '17 17:06

Sathish Kotha


1 Answers

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

like image 179
QoP Avatar answered Sep 18 '22 01:09

QoP