我不知道如何通过我的对象对象进行迭代(但它应该是数组): Data structure
错误:无法找到不同的支持对象' [object Object]'的 键入' object'。 NgFor仅支持绑定到Iterables,例如 阵列。
查看结构:
<a *ngFor="let msg of messages " href class="clearfix">
<div class="img-area"><img [ngClass]="{'photo-msg-item': !msg.from}"
src="{{ ( msg.from || (msg.from | baProfilePicture)) }}"></div>
<div class="msg-area">
<div>{{ msg.message }}</div>
<span>{{ msg.send_date }}</span>
</div>
</a>
组件:
public notifications:Array<Object>;
public messages:Array<Message>;
public data_error: Boolean = false;
constructor(private _baMsgCenterService:BaMsgCenterService) {
this.messages = this._baMsgCenterService.getMessages().subscribe(
(messagess) => {
let result:Array<Message> = [];
if (messagess) {
messagess.forEach((message) => {
result.push(
new Message(message[0],
message[1],
message[2],
message[3],
message[4])
);
});
}
this.messages = result;
},
err => { this.data_error = true}
);
答案 0 :(得分:1)
我认为你的问题就在这一行:
this.messages = this._baMsgCenterService.getMessages().subscribe(
您似乎正在尝试将Subscription
对象设置为messages
变量(subscribe
方法返回Subscription
对象https://github.com/ReactiveX/rxjs/blob/master/src/Observable.ts#L87)
所以你必须删除这个副作用。它应该是:
this._baMsgCenterService.getMessages().subscribe(
答案 1 :(得分:0)