首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >等待翻译完成- Ngx翻译

等待翻译完成- Ngx翻译
EN

Stack Overflow用户
提问于 2020-05-13 18:15:54
回答 1查看 444关注 0票数 1

我正在做一个项目,需要使用ngx翻译库翻译typescript文件中的文本,但我想等到翻译完成后再加载组件。我尝试了以下代码,但不起作用。

代码语言:javascript
复制
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');

第二种方法:

代码语言:javascript
复制
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');
EN

回答 1

Stack Overflow用户

发布于 2020-05-13 18:20:56

通过使用only then而不使用console.log,您可以在评估的promise中等待

代码语言:javascript
复制
console.log('start');
this.translateService.stream('Labels').toPromise().then(labels => {
  console.log(labels, 'check translation');
  console.log('end');
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61771970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档