在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.