加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular TranslateService翻译标签

发布时间:2020-12-17 06:51:47 所属栏目:安全 来源:网络整理
导读:在Angular中使用TranslateService我想要 title位于index.html中的标记使用不同的语言. title translateapplication.title/title 我翻译所有其他html标签,除非他们是自定义html标签,然后它是这样的: {{"document.name"|translate}} 问题可能是index.html在文
在Angular中使用TranslateService我想要< title>位于index.html中的标记使用不同的语言.

<title translate>application.title</title>

我翻译所有其他html标签,除非他们是自定义html标签,然后它是这样的:

{{"document.name"|translate}}

问题可能是index.html在文件夹中处于不同的级别

SRC
| -app
…. | – 翻译
| -index.html

解决方法

从 angular docs:

Title

Since an Angular application can’t be bootstrapped on the entire HTML document (<html> tag) it is not possible to bind to the text property of the HTMLTitleElement elements (representing the <title> tag). Instead,this service can be used to set and get the current title value.

您只需将Title服务与TranslateService结合使用即可

export class SomeComponent {
  constructor(private title:Title,private translate:TranslateService){}
  ngOnInit(){
    this.translateService.get("document.name").subscribe(name=>{
      this.title.setTitle(name);
    });
  }
}

请看看this cookbook.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读