AngularUniversal中的标题和meta标签在页面源代码中未更新。
创始人
2024-10-29 21:30:23
0

在app.module.ts中导入Meta和Title模块,并在导出中配置它们:

import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { RouterModule } from '@angular/router'; import { Meta, Title } from '@angular/platform-browser';

@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule.withServerTransition({appId: 'my-app'}), BrowserTransferStateModule, RouterModule.forRoot([ // your routes here ]) ], providers: [], bootstrap: [AppComponent] }) export class AppModule { constructor(private meta: Meta, private title: Title) { this.meta.addTags([ { name: 'description', content: 'My App' }, { name: 'keywords', content: 'Angular, Universal, Example' } ]); this.title.setTitle('My App'); } }

在AppComponent中的ngOnInit()函数中更新标题和meta标签:

import { Component, OnInit } from '@angular/core'; import { Meta, Title } from '@angular/platform-browser';

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { constructor(private meta: Meta, private title: Title) {}

ngOnInit() { this.meta.updateTag({ name: 'description', content: 'New description of the page' }); this.title.setTitle('New Title'); } }

这样就可以更新Angular Universal中的标题和meta标签,使其在页面源代码中正确显示。

相关内容

热门资讯

科普!鱼扑克辅助,德扑之星有作... 科普!鱼扑克辅助,德扑之星有作弊,必胜教程(果然有挂)您好,德扑之星有作弊,确实是有挂的,很多玩家在...
专家专科!wpk德州扑克靠不靠... 一、wepoke真的有挂简介了解软件请加微:136704302wepoke真的有挂是一款在线扑克游戏...
推荐一款!gg扑克发牌机制,w... 推荐一款!gg扑克发牌机制,wepoke辅助德之星,可靠技巧(本然有挂)1、不需要AI权限,帮助你快...
必知教程!德州ai辅助外挂,w... 必知教程!德州ai辅助外挂,we辅助poker德之星,扑克教程(切实有挂)1、很好的工具软件,可以解...
热点推荐!德扑赔率胜率计算,w... 热点推荐!德扑赔率胜率计算,wpk有外挂,解密教程(从来真的是有挂)1、金币登录送、破产送、升级送、...
重磅来袭!微扑克模拟器是什么,... 自定义德州之星辅助挂系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管你...
玩家必看科普!德扑ai软件购买... 玩家必看科普!德扑ai软件购买,aapoker发牌机制,线上教程(素来真的是有挂)1、在aapoke...
热点推荐!wepoke软件透明... 热点推荐!wepoke软件透明挂演示,德扑起手牌胜率图,细节方法(本来有挂)(1)热点推荐!wepo...
六分钟了解!wepoke软件收... 六分钟了解!wepoke软件收费吗,WePoKe透视挂,系统教程(原生真的是有挂);无聊就玩这款We...
玩家必知教程!德州ai辅助神器... 玩家必知教程!德州ai辅助神器燃油,wepokeai代打,实用技巧(本来存在有挂)1、金币登录送、破...