【发布时间】:2018-01-25 18:35:24
【问题描述】:
我是 TS 和 Angular 4 的新手。我需要能够在 Angular 材料 2 MdSnackBar 内向用户显示翻译后的 CLOSE 单词。我了解到您可以像这样在代码中调用 ngx-translate 翻译服务:
this.translate.get('ERROR.CLOSE').subscribe((res: string) => {
console.log(res);
});
问题是我需要能够在名为 MdSnackBar 的有角材料 2 元素中显示这一点。
我想这样执行它:
this.snackBar.open(error, this.getCloseWord(), {
duration: 10000,
})
private getCloseWord() {
this.translate.get('ERROR.CLOSE').subscribe((res: string) => {
console.log(res);
});
}
但我不知道如何使getCloseWord() 方法从可观察对象中返回正确的字符串值。
【问题讨论】:
标签: angular typescript rxjs angular-material2