【发布时间】:2020-05-23 07:10:34
【问题描述】:
我遇到了错误 = 找不到类型为“object”的不同支持对象“[object Object]”。 NgFor 仅支持绑定到 Iterables,例如 Arrays。其实我想做个通知列表,不知道自己犯了什么错误。
我遇到了错误 = 找不到类型为“object”的不同支持对象“[object Object]”。 NgFor 仅支持绑定到 Iterables,例如 Arrays。其实我想做个通知列表,不知道自己犯了什么错误。
HTML
<ng-container *ngIf="notificationModal">
<div class="side-panel__notif-container">
<div class="side-panel__notify-header">
<span class="side-panel__usr-profile-close" (click)="clkNotifcationPnl()">
<fa-icon [icon]="faClose"></fa-icon>
</span>
<span class="side-panel__usr-noti-hdr">Notifications</span><br>
</div>
<div class="side-panel__notify-body">
<div class="side-panel__user-notif-cont">
<div class="drop-content">
<ul class="mt-2 list-group notify-contents">
<li *ngFor="let items of notify">
<div class="col-md-3 col-sm-3 col-xs-3">
<div class="notify-img">
<span [ngStyle]="{'background-image': loadProfilePic()}" class="side-panel__user-notif-img fa"></span>
</div>
</div>
<div class="col-md-9 col-sm-9 col-xs-9 pd-l0">{{items.notifyFromName}}
<p>{{items.notifyMessage}}</p>
<p class="time">{{items.notifyDate}}</p>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</ng-container>
组件
public onClickUserNotif() {
this.headerService.isLoading = true;
return this.commonService.getNotificationList().subscribe((res) => {
if (res['status'].code === 0) {
this.headerService.isLoading = false;
let notify = res['notification']
if(notify.length > 0) {
this.notificationModal = true;
console.log(notify);
}
}
});
}
当我console.log(notify)时这个值出来了
【问题讨论】:
-
notify的作用域不是类,而是一个函数。this.notify = res['notification']会有意义 -
我已经按照你的代码,但是当我点击打开通知时,我仍然收到这个错误
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays -
@Pravu 是否为您提供了
line number的错误信息?错误发生在哪里? -
@DaneBrouwer 发生的错误`
- `
标签: angular typescript notifications