Angular 2: Difference between service and redux Angular 2: Difference between service and redux angular angular

Angular 2: Difference between service and redux


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.

Victor Savkin has an article on how to maintain state


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.


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.