angular - How can I update Observable, which used in async pipe? -


problem that: have simple component, renders "history" of messages. when app loaded, makes post-request, gets data , sets data observable this

this.messages$ = observable.of(messagesafterpostrequest); 

where public messages$: observable<any>;

this data rendered in template via async pipe:

let message of messages$ | async 

it works good, ....

i "new messages" via websocket, update list, created on previous step. trying use scan()

this.messages$ = this.messages$.scan((accmessage, nummessage) => {         console.log("inside current mesages", accmessage, nummessage)       }); 

in order "update" current list messages, console.logs looks never work, subscribe()

use instance of subject , push messages it:

const subject$ = new subject();  ...  subject.next(messagesafterpostrequest); 

... use template same way using async pipe.

maybe have @ replaysubject or behaviorsubject classes if want able previous messages well.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -