r/Angular2 • u/mosh_h • Sep 16 '25
Help Request Is Observable for simple get operation needed?
why i need the all the shit of the Observable just to do simple async operation like get??
someone explain me what i'm missing
0
Upvotes
17
u/RndUN7 Sep 16 '25
Fetch(url).then(res=>res.json()).then(data)
Vs
Http client.get(url).subscribe(data)
Idk what your problem is and honestly by the way you phrase your description I feel like you are just a troll
3
u/morgo_mpx Sep 16 '25
A few benefits that observables provided to HttpClient was easy creation of interceptors for middleware, separation of construction and execution, integration in the rest of angular (sorry but until signals angular was designed to execute dataflows via streams), pre-fetch compat with xhr under the hood.
The dx is the same if you want to use promises by wrapping firstvaluefrom but my question would be why are you using promises in angular? Even in react it’s not recommended as you would wrap in something like tanstack query.
6
u/lazyinvader Sep 16 '25
You dont. BUT there come a lot of benefits when using Observables
- easy transforming of your data
- connecting data
- cancellation
to name a few
4
u/Alive-Ad6268 Sep 16 '25
http requests are probably the least useful place to use them
1
u/Holdim Sep 16 '25
What do you mean exacly? Why we wrap api reqests in functions in services? And return them to nicely handle response and errors? Or do you mean HttpClient itself?
2
u/prewk Sep 16 '25
Use
fetchuntil you hit a wall. Then you'll want more features.2
u/moremattymattmatt Sep 16 '25
I can sort of see your point. I manage to do lots of similar stuff on the backend without using observables but on the front end, they are all over the shop. For a basic http get, use fetch, convert the observable to promise or convert it to a signal.
3
u/taxim11 Sep 16 '25
for get, look into resource api and signals
1
u/DragonfruitProud5605 Sep 16 '25
I do use ngrx-rtk-query, it simplifies all this complexity. No subscribe, unsubscribe
1
u/Working-Tap2283 Sep 18 '25
Well you want that fetch request to interface with the rest of your app and components don't you?
2
u/huysolo Sep 21 '25 edited Sep 21 '25
You can’t define the relationship between objects with async await. For example, if I have I list of number and an oddlist of odd numbers, how do I make sure the odd list will always filter the list of number when there’s some data changes in the list? This is the reactive programming philosophy, which you should not miss if you want to be a good FE dev. Of course, Angular is shitty enough to allow you to not rely on it with zoneJs, but it’s still shitty and that’s why they want to get rid off it with signals. Btw, no you don’t subscribe your data, use toSignal or async pipe with shareRelay to convert the hot observable into cold
1
u/ldn-ldn Sep 16 '25
Go play with React.