【发布时间】:2021-02-05 19:14:39
【问题描述】:
在对内容进行一些更改之前,我正在尝试使用 Angular 的 ngIf 检查我的 mat-panel 框的标题。
<mat-expansion-panel-header id="head">
<mat-panel-title>
Demo1
</mat-panel-title>
<img class="panel-image" src="assets/demo.png">
</mat-expansion-panel-header>
<mat-expansion-panel hideToggle>
<mat-expansion-panel-header id="head">
<mat-panel-title>
Demo
</mat-panel-title>
<img class="panel-image" src="assets/demo.png">
</mat-expansion-panel-header>
<div class="holder">
<mat-card id="CARDBOX" *ngFor="let box of box">
<img class="logoy" src="{{box.image}}" alt="Tesla" height=35px>
<a href="{{box.link}}" class="button">{{box.button_name}}</a>
<input type="image" id="info" title="Click for description" src="{{box.info}}" (click)="openDialog()" height=20px/>
</mat-card>
</mat-expansion-panel>
<mat-expansion-panel-header id="head">
<mat-panel-title>
Demo2
</mat-panel-title>
<img class="panel-image" src="assets/demo.png">
</mat-expansion-panel-header>
<mat-expansion-panel hideToggle>
<mat-expansion-panel-header id="head">
<mat-panel-title>
Demo
</mat-panel-title>
<img class="panel-image" src="assets/demo.png">
</mat-expansion-panel-header>
<div class="holder">
<mat-card id="CARDBOX" *ngFor="let box of box2">
<img class="logoy" src="{{box.image}}" alt="Tesla" height=35px>
<a href="{{box.link}}" class="button">{{box.button_name}}</a>
<input type="image" id="info" title="Click for description" src="{{box.info}}" (click)="openDialog()" height=20px/>
</mat-card>
</mat-expansion-panel>
由于我希望由 ngFor 生成标题,有没有一种方法可以在生成面板的正文内容之前使用 ngIf 检查哪个标题?喜欢
<ngIf title===Demo>
<mat-card **apply this**/>
我想这样做是因为我想使用 ngFor 生成标题和内容。可以用相同的方式生成标头,但是内容非常不同,因此需要检查将其放置在哪个标头下。这可以使用 ngIf 吗?
我想我正在尝试做的就像 python 或 java 中的 if 语句。如果标题是一回事,我想要它,然后用一些东西填充内容。如果标题是其他内容,则使用其他内容填充内容。这有意义吗?
【问题讨论】:
-
你能分享你的 ngFor 循环吗?
-
是的,已经编辑过了。
-
还有一点,具有相同值的多个 Id 不是有效的 HTML。我建议从所有元素中删除它。在 Angular 中,您几乎不需要 Id 属性。
-
我应该改用类吗?
标签: html css angular if-statement angular-material