Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda