Search code examples
angularionic4ngrxionic-storage

How to use ionic storage (local database) with ngrx in an ionic angular application


How to use ionic storage (local database) with ngrx in an ionic angular application?

I found some resources about using ngrx with a database as an api, or about ionic-storage. But I am stuck in putting them all together (loading data - crud operations - effects - representing observable data ...).

I am trying this , but my problem is that it is using http which returns an observable in the dataservice, while I am working with ionic storage which returns a promise.

Notice that it is my first ionic angular application!

I need to know best practices to accomplish this task, where to user promise in this specific case, and if I need to use observable in the state or ...


Solution

  • The problem was in the way I was dealing with the promise (in my code), so I used the same code in this tutorial.

    The difference is that I used ionicstorage instead of getting data with http requests, Ionic storage get() and set() methods return promises but I converted the promises in the dataservice to observables.

    At the end my problem was solved - I don't know if I am making best practices!!

    Please if you need the entire code tell me and I will be happy to help.