Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Offline and Online Functionality in Angular 2/4

I have to implement a Offline and Online functionality on the click of the button.

  1. When user clicks button A, the whole application should go to offline mode (i.e. the pages needs to cached & any new entries in the form will be stored in browser's memory)
  2. When user clicks button B, the stored data need to be pushed to the DB.

Please help me how can I achieve this functionality.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

DIY version:

First, you need to put a switch in your service. If it is under local mode, cache or store all data on client side. It'd better to have a flag in data for judging if data has been synced to server or not. If it is under server mode, do whatever it is needed to push all data to server side.

Second, you will need a monitor service in background or when server mode is enabled, syncing action will be kicked once. The action or background process will check any not synced data and push them to server. When it is done, flag it as synced.

That is the general idea.

Code of my idea to achieve this. Create a parent service class:

class BaseService {
    protected execute(online: any, offline: any){
        if (this.config.mode == 'online')
            online();
        else
            offline();
    }
}

In actual child service

... extends BaseService {
    saveEmployee() {
        this.execute(() => {
            // do online stuff
        }, () => {
            // do offline stuff
        });
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!