
กำหนด HTML Meta Tags ด้วย Angular
***Angular Meta service ใช้ได้ตั้งแต่ Angular 4+ เป็นต้นไป updateTag ใช้สำหรับ update tag เดิม (ไล่มาจาก HomeComponet || component แรกที่ถูกเรียก)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import {Meta, Title} from "@angular/platform-browser"; export class ViewComponent implements OnInit { ngOnInit( ) { this._setMetaAndLinks(); } private _setMetaAndLinks(){ this.title.setTitle(this.PostTitle); this.meta.updateTag({ name: 'description', content: this.PostTitle + ' - Kaset.info' },`name='description'`); this.meta.updateTag({ property: 'og:title', content: this.PostTitle + ' - Kaset.info' },`property='og:title'`); this.meta.updateTag({ property: 'og:image', content: 'https://www.kaset.info/u/'+this.photo.FileName },`property='og:image'`); } } |
addTags ถ้าอยากเพิ่ม mata เข้าไปใหม่
1 2 3 |
this.meta.addTags([ { name: 'twitter:site', content: 'https://www.kaset.info' }, ]); |