禁止 JhiAlertService 使用 TranslateService 翻译消息
Disable JhiAlertService from using TranslateService to translate message
当我使用我的服务打印消息时,JhiAlertService 会尝试翻译消息,我该如何禁用?
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { JhiAlertService } from 'ng-jhipster';
@Injectable({
providedIn: 'root'
})
export class MessageServiceService {
constructor(public translate: TranslateService, public alertService: JhiAlertService) {
this.getTranslations();
}
getTranslations(){
this.clientError1 = this.translate.instant('global.error.clientError1');
this.clientError2 = this.translate.instant('global.error.clientError2');
}
printError(name, clientnumber) {
this.alertService.error(
this.clientError1 + name + this.clientError2 + clientnumber
);
}
}
很遗憾,我还没有找到不激活翻译的方法;
然而,要解决这个问题,只需按如下方式在参数之间传递变量即可:
字符串:
MSG_STR: "Hello {{user}}"
警报命令:
this.alertService.error(MSG_STR, {user: 'Max'}));
结果:
Hello Max
当我使用我的服务打印消息时,JhiAlertService 会尝试翻译消息,我该如何禁用?
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { JhiAlertService } from 'ng-jhipster';
@Injectable({
providedIn: 'root'
})
export class MessageServiceService {
constructor(public translate: TranslateService, public alertService: JhiAlertService) {
this.getTranslations();
}
getTranslations(){
this.clientError1 = this.translate.instant('global.error.clientError1');
this.clientError2 = this.translate.instant('global.error.clientError2');
}
printError(name, clientnumber) {
this.alertService.error(
this.clientError1 + name + this.clientError2 + clientnumber
);
}
}
很遗憾,我还没有找到不激活翻译的方法;
然而,要解决这个问题,只需按如下方式在参数之间传递变量即可:
字符串:
MSG_STR: "Hello {{user}}"
警报命令:
this.alertService.error(MSG_STR, {user: 'Max'}));
结果:
Hello Max