仅显示 *ngIf 表达式的第一个匹配项
Show only first match from *ngIf expression
如何只显示 *ngIf 中的一个(第一个)匹配项。
我有一个对象循环,其中 *ngFor 后跟 *ngIf 表达式,其中包含具有相同 ID 和不同日期的项目。
我想过滤并仅显示日期最近的那个,而不是复制它们,因为我按 objectId 过滤。
在 html 文件中:
<div *ngFor="let item of list">
<div *ngIf="item.id == matchWithCondion ?func():false">
Add your code here
</div>
</div>
在打字稿文件中初始化一个变量为:
let isFirstMatch = false;
constructor(){}
func() {
if (!isFirstMatch) {
this.isFirstMatch = true;
return true;
} else {
return false;
}
}
在 html 文件中:
<div *ngFor="let item of list">
<div *ngIf="item.id == matchWithCondion ? func() : false">
Add your code here
</div>
</div>
在打字稿文件中初始化一个变量为:
let isFirstMatch = false;
如何只显示 *ngIf 中的一个(第一个)匹配项。
我有一个对象循环,其中 *ngFor 后跟 *ngIf 表达式,其中包含具有相同 ID 和不同日期的项目。 我想过滤并仅显示日期最近的那个,而不是复制它们,因为我按 objectId 过滤。
在 html 文件中:
<div *ngFor="let item of list">
<div *ngIf="item.id == matchWithCondion ?func():false">
Add your code here
</div>
</div>
在打字稿文件中初始化一个变量为:
let isFirstMatch = false;
constructor(){}
func() {
if (!isFirstMatch) {
this.isFirstMatch = true;
return true;
} else {
return false;
}
}
在 html 文件中:
<div *ngFor="let item of list">
<div *ngIf="item.id == matchWithCondion ? func() : false">
Add your code here
</div>
</div>
在打字稿文件中初始化一个变量为:
let isFirstMatch = false;