【发布时间】:2020-05-13 18:48:50
【问题描述】:
我正在开发一个项目,该项目需要使用 ngx 翻译库翻译 typescript 文件中的文本,但我想等到翻译完成后再加载组件。我尝试了以下代码,但没有成功。
console.log('start');
this.lables = await this.translateService.stream('Labels').toPromise().then(res => res);
console.log(lables , 'check translation'); // it show nothing
console.log('end');
第二种方法:
console.log('start');
this.lables = await this.translateService.stream('Labels').pipe(take(1)).toPromise().then(res => res);
console.log(lables , 'check translation'); // it show "Labels" as a string.
console.log('end');
【问题讨论】:
标签: javascript angular rxjs ngx-translate