Updating of variants OnInit - Angular 2

1

I have the variable:

compromissoInicio = ‘’;

No onInit , I have:

this.enviaForm(this.funcoes.homeAtualiza);

That is, if homeAtualiza is true , the system updates the information as follows:

... submita form ...
this.compromissoInicio = retorno[‘compromisso_inicio’];

In HTML, I have:

{{ compromissoInicio | date:‘dd/MM/yyyy HH:mm:ss’ }}

The problem is that if homeAtualiza is true , every time you return to the home page, the system will unnecessarily query the webservice.

And, if homeAtualiza is false , the content of {{ compromissoInicio | date:‘dd/MM/yyyy HH:mm:ss’ }} is empty.

I need a way that compromissoInicio always stays with the last content loaded, if the page is not updated, in onInit .

    
asked by anonymous 05.12.2018 / 15:27

1 answer

1

You can leave this variable in the service and feed it as soon as it receives the value from the webservice. and when it is false, you will analyze if this variable is worth if it is null then yes you consume the web service again.

    
11.12.2018 / 05:02