双模板搜索在角度

发布于 2025-02-09 21:24:32 字数 803 浏览 0 评论 0原文

一方面,我有一个链接列表,这些链接显示如下所示

<mat-nav-list>
  <mat-list-item *ngFor="let link of links">
    <a matLine href="{{link.url}}"> {{ link.label }} </a> 
  </mat-list-item>
</mat-nav-list>

:另一方面:

class SideNavItem {
  label: string;
  url: string;
}
[...]
this.links = [ { label: "users", url:"users"},  { label: "tickets", url:"tickets"}];

另一方面,我一直在使用'@ngx-translate/core'进行翻译,并且我使用它如下:

<mat-card-header>
  <mat-card-title>{{'cards.title'|translate}}</mat-card-title>
</mat-card-header>

但是现在,我想将我的翻译模块用于列表项目标签。我正在尝试结合两个插值,类似 &lt; matline href =“ {{link.url}}”&gt; {{{{link.label}} |翻译}}}&lt;/a&gt;,但这引发了一个错误,说这是语法错误。

有什么想法如何插值两次?

On one hand, I have a list of links that gets displayed as follows

<mat-nav-list>
  <mat-list-item *ngFor="let link of links">
    <a matLine href="{{link.url}}"> {{ link.label }} </a> 
  </mat-list-item>
</mat-nav-list>

in the *.ts:

class SideNavItem {
  label: string;
  url: string;
}
[...]
this.links = [ { label: "users", url:"users"},  { label: "tickets", url:"tickets"}];

On the other hand, I have been using '@ngx-translate/core' for the translation, and I use it as follows:

<mat-card-header>
  <mat-card-title>{{'cards.title'|translate}}</mat-card-title>
</mat-card-header>

But now, I want to use my translate module for the list item labels. I am trying to combine both interpolations, something like
<a matLine href="{{link.url}}">{{ {{link.label}} | translate }}</a> , but this is throwing an error saying that it is a syntax error.

Any ideas how to interpolate twice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人九事 2025-02-16 21:24:32

当您使用{{...}}时,您已经在Angular中。就像您有工作的示例一样,只需添加|像So:

&lt; matline href =“ {{link.url}}”&gt; a matline href =“ {{link.label |翻译}}}&lt;/a&gt;

You're already within angular when you're using {{ ... }}. Like the example where you have it working just add | translate in the dom like so:

<a matLine href="{{link.url}}"> {{ link.label | translate }} </a>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文