gpt4 book ai didi

javascript - 添加/更新元标记在 angular5 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 01:31:39 25 4
gpt4 key购买 nike

我使用下面的代码在运行时在 angular5 中添加或更新元标记

import { Title ,Meta} from '@angular/platform-browser'; 
constructor( private meta:Meta)
{
this.meta.addTags([
{name: 'description', content: 'How to use Angular 4 meta
service'},
{name: 'author', content: 'talkingdotnet'},
{name: 'keywords', content: 'Angular, Meta Service'}
]);
this.meta.updateTag({ name: 'description', content: 'Angular 4 meta service'
});
}

在应用模块中导入元服务

但它不起作用(不在我的页面源代码中)。任何人都可以帮助我

谢谢

最佳答案

你只需要改变:

this.meta.updateTag({ content: 'Angular 4 meta service'} , 'name="description"' );

WORKING DEMO (而不是通过检查元素查看页面源代码检查)原因解释如下

您的方法也 100% 正常工作,您可以在我给定的演示中进行检查。


Angular is not served from server side , that's why you can see any meta tags via page view source , any thing that is being changed after page loads that won't be shown in page view source

If you want to check the updated meta tags you need to inspect element and check there

If you want to server side rendering then you can go for Angular Universal

关于javascript - 添加/更新元标记在 angular5 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48181368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com