html - Angular 5设置带有html转义(实体)字符的文档标题

标签 html angular typescript angular5

看起来很简单,但我找不到简单的解决方案。 我正在使用标题服务将标题放在文档中。这工作正常,请参阅此处的文档: https://angular.io/guide/set-document-title

我的问题是特殊字符。在我的代码中,标题是由路由服务设置的,但我的页面标题有特殊字符。举个例子:页面标题“Início”,í 字符格式不正确。

Angular 中有一些函数或服务可以做到这一点吗?

我的代码,问题出在setTitle:

AssinarEventosRoute(): any {
        this.router.events
            .filter((event) => event instanceof NavigationEnd)
            .map(() => this.activatedRoute)
            .map((route) => {
                while (route.firstChild) route = route.firstChild;
                return route;
            })
            .filter((route) => route.outlet === 'primary')
            .mergeMap((route) => route.data)
            .subscribe((event) => this.titleService.setTitle(`${event['title']} | Gerencial ISP 2`));
    }

最佳答案

您必须在 HTML 文件中添加字符集标记:

<meta charset="utf-8">

此外,您的 .ts 文件也应该采用 UTF-8 编码。

Angular-CLI/Angular2: Non-standard chars only load correctly in index.html, not in components via ng serve

Angular template view with utf-8 chars doesn't work

关于html - Angular 5设置带有html转义(实体)字符的文档标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49652573/

相关文章:

javascript - Angular 2 Observables - 对 Action 的空响应仍然显示数组中的数据

javascript - 如何使用 Typescript 编译 .NET 程序集以便与 Unity3d 一起使用?

javascript - 选择具有边框半径的 div 后删除框

javascript - 如何将ListBox的高度设置为自动

javascript - 对象没有被正确解释 JavaScript

javascript - 如何在 vue js html 中使用数组检查 v-if 条件?

angular - IntelliJ 错误地建议在 Angular 应用程序中将方法设为静态

angular - 找不到名称为 : formControlName in angular reactive form 的控件

typescript - TypeORM单表继承更新实体类型

angular - 箭头函数隐式返回自动用括号包裹