r/Angular2•
TimGeerts

Observables best practice

Help Request

So, I've just gotten into learning angular again (been since 1.1 or something) and am currently looking at observables.
I've created a simple application that loads data from an API and displays it in a table.
As far as I'm aware, I can do two things;

  • Load the data into an observable and subscribe to it in my typescript, effectively just passing an "unwrapped" array to my view.
  • Straight up pass the observable to my view and use the "async" pipe. (currently chose this approach)

Is there any reason to do one over the other?

And then, maybe more important, I'm planning on adding a search component and a pagination component to my table, and I'm currently smashing my head up against the fact that my data (table data) is still an observable and it's a bit difficult to combine two components that alter that observable (pagination slices the resulting array, search filters it).
Is it better for me to work with a "simple" array (subscribing and unsubscribing from the observable? Or, is this perfectly doable with Observables?

Posted Apr 24, 2018, 8:58 AM UTC

139
Loading comments…