Angular 2 Updating objects in “real time.”

前端 未结 1 1055
旧巷少年郎
旧巷少年郎 2021-02-10 21:59

Hi I’m trying to wrap on how to update a table angular 2.

Here is what I have: Backend: express / MongoDB. Updates are feed into the DB via an external app Data: 90% da

1条回答
  •  暖寄归人
    2021-02-10 22:25

    1. Observables are event-based so they can be used to receive events from server leveraging web sockets. Have a look at this article (section "Event-based support"):

      • https://jaxenter.com/reactive-programming-http-and-angular-2-124560.html
    2. In fact it's new objects but you can leverage the scan operators to aggregate the content of several events.

      var obs = (...)
      obs.startWith([])
         .scan((acc,value) => acc.concat(value))
         .subscribe((data) => {
           console.log(data);
         });
      

      See this question for more details:

      • Convert a plain string[] into a Observable and concat it to another Observable using RxJS 5
    3. If you want to pull with a time interval, you can leverage the interval method:

      Observable.interval(3000).flatMap(() => {
        return this.http.get('/some-request').map(res => res.json());
      }).subscribe((data) => {
        console.log(data);
      });
      

    0 讨论(0)
提交回复
热议问题