使用 angular 翻译作为通知函数的参数

Use angular translation as parameter of a notification function

我希望能够将字符串消息作为参数传递给我的函数。 matToolTip 工作正常,但我没有到达将其传递给我的函数 AddRemoveUserOfGroupGeneral :

<button mat-raised-button color="primary" matTooltip="{{ 'GROUPS.addUserToGroup' | translate }}" matTooltipPosition="above" (click)="AddRemoveUserOfGroupGeneral('add', 'I WANT MY VARIABLE GROUPS.addUserToGroup THERE ?');">Ajouter <mat-icon>add_box</mat-icon></button>

Angular 11 打字稿 4.0.5 感谢您的帮助!

如果你想在你的打字稿中翻译消息并且你正在使用 ngx-translate 只需在你的组件中导入 TranslateService 并在构造函数中声明它

import { TranslateService } from '@ngx-translate/core';

并更新您的构造函数以添加 public translate: TranslateService

constructor(public translate: TranslateService) {}

现在你可以在任何地方使用这个this.translate.get('myKey');,根据你的情况

AddRemoveUserOfGroupGeneral(arg1,key){
  ...
  let message = this.translate.get(key);
  console.log(message)
  ...
}

现在只需从您的 HTML 模板传递密钥

<button mat-raised-button color="primary" matTooltip="{{ 'GROUPS.addUserToGroup' | translate }}" matTooltipPosition="above" (click)="AddRemoveUserOfGroupGeneral('add', 'GROUPS.addUserToGroup');">Ajouter <mat-icon>add_box</mat-icon></button>