我有Observer Stream,对象从服务中获取
getmessages(){return this.message$.asObservable()}
在我看来
<div class="messages-left" *ngIf="messages$ | async as message; else loading">
<div class="slim-pageheader">
<h6 class="slim-pagetitle">Messages</h6>
<ion-list no-lines>
<ion-item >
<ion-avatar item-left>
<img src="">
</ion-avatar>
<div >
<h3>{{message.content}}</h3>
</div>
</ion-item>
</ion-list>
</div>
但仅显示最后一条消息,而不是所有消息流
答案 0 :(得分:0)
是的,当我在服务中更改一些方法时,您现在就可以正确地工作了
messagearray : MessageViewModel[] = []
getMessages()
{
this._hubConnection.invoke(“ GetMessages”).then((messagedata:MessageData [])=> {
this.messagearray = messagedata;
this.message$.next(this.messagearray)
})。catch(err => {console.log(err)})
}
现在,当我收到来自任何用户的新消息时,我会将新消息推送到数组
this._hubConnection.on("MessageReceived", (message) =>
{
this.messagearray.push(message)
this.message$.next(this.messagearray)
})