等待翻译完成-Ngx翻译

问题描述 投票:0回答:1

我正在一个需要使用ngx翻译库翻译打字稿文件中的文本的项目,但是我想等到翻译完成后再加载该组件。我尝试了以下代码,但没有用。

console.log('start');
const lables = await this.translateService.stream('Labels').toPromise().then(res => res);
console.log(lables , 'check translation');  // it show nothing 
console.log('end');

第二方法:

console.log('start');
const 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
1个回答
0
投票

您可以仅在不使用await的情况下使用console.log来评估承诺中的内容>

console.log('start');
this.translateService.stream('Labels').toPromise().then(labels => {
  console.log(labels, 'check translation');
  console.log('end');
});
© www.soinside.com 2019 - 2024. All rights reserved.