1

i have a service PhoneService calling (in the constructor) a remote API to get data and populate DB, the AppComponent use the PhoneService (ngOnInit) to get data from Dexie table. in the first page load i have no data (it's normal because AppComponent call function to get data before the PhoneService populate Dexie DB)

my question is : how can i tell my PhoneService to wait unit pupulation ending and then fetch the Dexie table to get data ?

First page load : Check if Data in my Dexie Table (0 record) -> Calling API -> Populate Dexie DB -> fetch Dexie Table (No data because angular fetch Dexie table before, data population end )

Second+ page load : Check if Data in my Dexie Table (ok) -> fetch Dexie Table (OK)

thank you

Man Doe
  • 11
  • 1
  • 3

1 Answers1

1

typically, you have to use promises to synchronise everything.

Have a look at this thread, you will understand : Angular2: How to load data before rendering the component?

sancelot
  • 1,905
  • 12
  • 31
  • thanks @sancelot, I have no problem when I use direct call to my API, the problem is when I : Call API -> populate DB -> fetch Dexie Table – Man Doe Mar 12 '18 at 15:24