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

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.