Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 等待翻译完成-Ngx翻译_Javascript_Angular_Rxjs_Ngx Translate - Fatal编程技术网

Javascript 等待翻译完成-Ngx翻译

Javascript 等待翻译完成-Ngx翻译,javascript,angular,rxjs,ngx-translate,Javascript,Angular,Rxjs,Ngx Translate,我正在做一个项目,需要使用ngx翻译库翻译typescript文件中的文本,但我想等到翻译完成后再加载组件。我尝试了以下代码,但没有成功 console.log('start'); this.lables = await this.translateService.stream('Labels').toPromise().then(res => res); console.log(lables , 'check translation'); // it show nothing con

我正在做一个项目,需要使用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');

您可以通过使用only then而不使用wait命令在已评估的承诺内console.log

console.log('start');
this.translateService.stream('Labels').toPromise().then(labels => {
  console.log(labels, 'check translation');
  console.log('end');
});

您可以通过使用only then而不使用wait命令在已评估的承诺内console.log

console.log('start');
this.translateService.stream('Labels').toPromise().then(labels => {
  console.log(labels, 'check translation');
  console.log('end');
});

我试过了,它将标签显示为字符串而不是内容。您需要调查
this.translateService.stream('Labels')
它返回什么?它应该返回一个json对象,其中包含翻译后的单词列表。它这样做了吗?那么您需要看看如何通过使用我尝试过的这个.translateService.stream('Labels')来正确获取该对象,它将标签显示为字符串,而不是您需要调查
this.translateService.stream('Labels')的内容
它返回什么?它应该返回一个json对象,该对象包含已翻译单词的列表。它这样做了吗?那么您需要了解如何通过使用这个.translateService.stream('Labels')正确地获取该对象