双模板搜索在角度
一方面,我有一个链接列表,这些链接显示如下所示
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用
{{...}}
时,您已经在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>