首页 > 解决方案 > 如何更改离子应用程序的标题

问题描述

我的应用程序与 GTM(谷歌标签管理器)连接。我想查看用户的所有页面浏览量,但我只看到 Ionic 应用程序。index.html 中的标题是静态的,但我可以这样做动态吗?

标签: angularcordovaionic-frameworkgoogle-tag-manager

解决方案


在您的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文件的标题。


推荐阅读