What is the need of redux because we can also save and get data from services, as far as I understand we can also get and save data into services and those services could be used by other components.
-
4Does this answer your question? [Angular 6 - Why use @ngrx/store rather than service injection](https://stackoverflow.com/questions/51274343/angular-6-why-use-ngrx-store-rather-than-service-injection) – Andreas is moving to Codidact Aug 13 '20 at 03:15
3 Answers
You don't need redux, but you do need a way to maintain state. A service will do, but in the end you will send up with something resembling redux or ngrx store.
Consider the challenge. You have data coming in asynchronously. You want it reactive. You want to have error handling. You want to have waiting states as data is updated. You have cascading scenarios where one event triggers multiple actions, each with its own latency and error paths.
And you want to set up a pattern that can be used in multiple components.
Victor Savkin has a way of doing this with observables which is very slick. Ngrx has another way.
I wrote a moderately complex component using a service. It worked ok. Hours would disappear into tracking down some odd situations where the state was undefined and threw errors. I was getting far too much into the weeds to have something reusable as a pattern. And the result was fragile and brittle. It wasn't fully reactive, and to make it was proving extremely difficult and time consuming. I ported it to ngrx, and once the learning curve is surmounted, which isn't trivial, the code became simpler and fully instrumented allowing quick debugging.
YMMV.

- 1,767
- 13
- 15
-
Any link regarding Victor Savkin way or doing this with observables? – Chuck Mah Aug 11 '17 at 13:01
A service is an Angular implementation detail. Whereas redux is an architectural concept. The two are not directly comparable.
If you are interested how redux can be applied to Angular, I would recommend reading the Comprehensive Introduction to @ngrx/store
.

- 57,105
- 17
- 163
- 197
-
-
There is plenty of material extolling the benefits of redux. It should not be hard to find. Perhaps a more interesting question is this one: [what are the disadvantages of storing all your state in a single immutable atom?](https://github.com/reactjs/redux/issues/1385) – cartant Aug 12 '16 at 07:16
-
what is the best source to learn ngrx, is it has official documentation? – blackHawk Aug 12 '16 at 14:43
-
Wait . Read this from Angular docs: 1) *In Angular, a service is an instance of a class that can be made available to any part of your application*; 2) *Services are the place where you share data between parts of your application*. Does it ring the bell? Doesn't it look like Redux global state? For me, it is very much like Redux state. I'm new to Angular and don't understand it yet and fighting it and its concepts. – Green Jun 26 '19 at 09:25
-
That's actually wrong. Redux is a library - thus an "implementation detail" as well. See e.g. https://redux.js.org/ I think you're confusing redux with the Flux pattern, see e.g. https://en.wikipedia.org/wiki/React_(JavaScript_library) – carl-johan.blomqvist Oct 08 '21 at 09:00
A service is a Angular feature that will allow user to manage their common methods and properties.But the state pattern which provide the structure way to manage our application state ( properties that commonly used through the application ).
If you are interested to lean Angular state pattern i would recommend @ngrx/store
&& @ngxs/store
. both will be a good one. i would suggest ngxs
which is more simple than to compare @ngrs/store
implementation and it have the clear documentation to learn.

- 2,287
- 8
- 23
- 49

- 123
- 1
- 4
- 14