Angular promise multiple times

Viewed 1751

I'm trying to replicate a couchDB like system. My backend is Parse server and my frontend is Ionic (1)

What i'm trying to achieve is to fasten my application with localstorage.

Currently: GetUserAds

-> Has localstorage?

--> Yes

---> Return localstorage

--> No

---> Get database call

----> Return and put local

But what i really would like is the local return to fetch the database in background and return that data as well if it's changed

This is because my application has many users and changes a lot.

Could i do something like this.

getUserAds(user).then(function(data) {
//Local data
}).then(function(dataDB) {
//Database updated data
})
2 Answers
Related