Angular 有没有办法计算html页面中所有的循环布尔值
有没有办法计算html页面中所有的循环布尔值Angular 有没有办法计算html页面中所有的循环布尔值,angular,Angular,有没有办法计算html页面中所有的循环布尔值 this.items = [{ id:1, isUpdate: false }, { id:2, isUpdate: true }, { id:3, isUpdate: true } 只要其中一个isUpdate值为true,通知组件就会显示并且只显示一次,无论有多少isUpdate值为true 我想知道是否有办法计算app.component.html页面中的布尔值,以查看是否至
this.items = [{
id:1,
isUpdate: false
},
{
id:2,
isUpdate: true
},
{
id:3,
isUpdate: true
}
只要其中一个isUpdate值为true,通知组件就会显示并且只显示一次,无论有多少isUpdate值为true
我想知道是否有办法计算app.component.html页面中的布尔值,以查看是否至少有一个isUpdate值为true,并显示通知组件。我不想多次显示通知组件,只显示一次
到目前为止,我的代码如下所示,它将多次显示通知:
app.component.html
<div *ngFor = "let notification of items">
<notification *ngIf="notification.isUpdate"></notification>
</div>
app.component.html
及
Notification.component.html
准备更新。
提前感谢。编写一个函数,如果显示通知,该函数将返回:
showNotification(): boolean {
this.items.forEach(item => {
if (item.isUpdate) {
return true;
}
});
return false;
}
并将其绑定到模板:
<notification *ngIf="showNotification()"></notification>
编写一个函数,如果显示通知,该函数将返回:
showNotification(): boolean {
this.items.forEach(item => {
if (item.isUpdate) {
return true;
}
});
return false;
}
并将其绑定到模板:
<notification *ngIf="showNotification()"></notification>
Hi Patryk,感谢您的快速回复。在showNotification函数中,无论item.isUpdate为真/假,最终都会返回false。不客气。如果您的问题答案正确,请将其标记为已解决。我已将其更改如下,效果非常好。再次感谢你。showNotification():boolean{let result:boolean=false;this.items.forEach(item=>{result=result | | | item.isUpdate;});if(result){return true;}else{return false;}Hi Patryk,感谢您的快速回复。在showNotification函数中,无论item.isUpdate为真/假,最终都会返回false。不客气。如果您的问题答案正确,请将其标记为已解决。我已将其更改如下,效果非常好。再次感谢你。showNotification():boolean{let result:boolean=false;this.items.forEach(item=>{result=result | | | item.isUpdate;});if(result){return true;}else{return false;}