我可以在index.html中使用Meta概念中的角度4動態設置標籤。但是,當我嘗試刪除tags.its而不是 刪除時,如何刪除標記我之前添加的任何內容?如何使用Meta中的角度刪除標籤4
這裏是我的嘗試: 設置標籤:
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'");
}
}
在destroy方法,我去掉標籤,但這些標籤不刪除,我怎麼能刪除標記? 跟着這個:meta tags blog
是你摧毀叫什麼名字?你確認了嗎? – CharanRoot
其調用銷燬方法 –
我在代碼中看不到任何問題。試試這個this.meta.addTag({name:'og:title',content:'Grace'})。如果在removetag嘗試getTag和打印輸出控制檯日誌之前仍然不工作。 – CharanRoot