javascript - NgxTranslate 不适用于 HTTP 拦截器
问题描述
我正在使用 ngxtranslate 翻译应用程序。它就像魅力一样。问题是我有 HttpInterceptor,它一开始就试图从本地存储中获取数据,如果询问您是否要加载最后的更改或关闭,它会显示一个对话框。
问题是对话框中的文本没有翻译,我不知道该怎么做,因为它无处不在。
HTTP拦截器文件
import { TranslateService } from '@ngx-translate/core';
@Injectable()
export class CacheInterceptor implements HttpInterceptor {
constructor(private cacheService: HttpCacheService, private dialog: MatDialog, private translate: TranslateService) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return from(this.handle(req, next));
}
.......
const cachedResponse: HttpResponse<any> =
this.cacheService.get(reqId);
if (cachedResponse) {
console.log('cache hit');
const dialogResult = await this.openDialog();
if (dialogResult) {
console.log('Loading item from cache');
// return modifyied response
.........
async openDialog() {
const dialogData = new ConfirmationDialogModel(
await this.translate.instant('some.text'),
await this.translate.instant('some.anotherText')
);
....
输出是公正的some.text
,some.anotherText
我该怎么做才能让它工作?
解决方案
你试试看?
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
openDialog()
return from(this.handle(req, next));
}
推荐阅读
- matlab - 文件标识符可以在 Matlab fprintf 中指定一个字符串作为输出吗?
- macos - webcal:// 链接不再在 MacOS 上打开 Apple 日历
- javascript - 如何使用外部 HTML 文件制作 Web 组件?
- c++ - 如何在 c++11 中的默认移动构造函数末尾添加打印语句?
- python-3.x - 如何在 AWS Cloud9 中安装 chromedriver?
- git - 如何使用 XAMPP 在 Windows 10 上修复 git-backend-http 的重定向问题
- puppet - Puppet Enterprise 中无法识别的服务
- javascript - 无法获取 javascript 天气 api 应用程序来显示天气
- android - 有没有办法指定用户使用本机相机而不是任何其他应用程序。(Cordova/Ionic)?
- dataframe - 在 pyspark 中加入两个数据框