[英]*ngIf Angular4 issue
I am trying to work on a block of code where I can use *ngif else in introduced recently, I am hoping to see "system has no alerts" when alerts is None. 我正在尝试处理代码块,可以在最近介绍的代码中使用* ngif else,我希望当警报为None时看到“系统没有警报”。 Can some please explain to me what I am doing wrong.
可以给我解释一下我在做什么错。 Any comment would be really helpful.
任何评论将非常有帮助。
<ul class="al-msg-center clearfix">
<li class="dropdown">
<a href class="dropdown-toggle" id="msg-dd1" data-toggle="dropdown" aria-expanded="false">
<i (click)="refreshAlerts()" class="fa fa-bell-o"></i>
<span *ngIf="alerts.length">{{alerts.length}} </span>
<div class="notification-ring"></div>
</a>
<div class="top-dropdown-menu dropdown-menu" aria-labelledby="msg-dd1">
<i class="dropdown-arr"></i>
<div class="msg-list">
<div *ngIf="alerts; else noAlerts">
<a *ngFor="let msg of alerts" href class="clearfix">
<div class="msg-area">
<div>{{ msg.message }}</div>
<span>{{ msg.level }}</span>
</div>
</a>
</div>
<ng-template #noAlerts>
<div class="msg-area">
<div>"The system has no alerts"</div>
</div>
</ng-template>
</div>
</div>
</li>
With current code as soon as alerts
exists, it will try to display content without looking at how much element alerts
array has. 对于具有
alerts
现有代码,它将在不查看alerts
数组有多少元素的情况下尝试显示内容。
You should check alerts.length
to get accurate result. 您应该检查
alerts.length
以获得准确的结果。
*ngIf="alerts?.length; else noAlerts"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.