angular - 如何更改离子应用程序的标题
问题描述
我的应用程序与 GTM(谷歌标签管理器)连接。我想查看用户的所有页面浏览量,但我只看到 Ionic 应用程序。index.html 中的标题是静态的,但我可以这样做动态吗?
解决方案
在您的app.component.ts
文件中导入Title
类,@angular/platform-browser
并将其添加到构造函数中。然后添加下面提到的代码
ngOnInit() {
this.router.events
.pipe(filter((event) => event instanceof NavigationEnd))
.subscribe((event: any) => {
const title = event.url;
this._title.setTitle(`${title}`);
});
}
这样,您将能够更改index.html
文件的标题。
推荐阅读
- swift - Swift UICollectionView,最后一个单元格添加另一个单元格
- java - 我将如何解决“非法开始表达”?
- sql - BigQuery SQL 排除某些值出现在不同列中的行
- javascript - Gatby 控制台警告您的数据中存在冲突的字段类型。在同一查询上两次使用 createPage 时
- c# - Entity Framework Core - 我可以直接查询子属性中的列表/对象,避免多次重复 Include/ThenInclude 吗?
- reactjs - 我们如何根据索引更新动态对象数组的状态
- r - 从命名列表中提取元素,同时将名称保留在 R 中
- azure - 通过 Startup.cs 向 Azure Functions 添加依赖项注入会导致主机错误
- highcharts - Highcharts 热图设置列宽
- javascript - 在 React JS 中,没有使用按钮的 onClick 事件呈现 HTML 元素