Oninit variable upgrade - Angular 2

Asked

Viewed 28 times

1

I have the variable:

compromissoInicio = ‘’;

In the onInit, have:

this.enviaForm(this.funcoes.homeAtualiza);

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

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

In HTML, I have:

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

The problem is that, case homeAtualiza be it true, every time you return to the home page, the system will unnecessarily consult the webservice.

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

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

1 answer

1

You can leave this variable in the service and feed it as soon as you receive the value of the webservice. and when it is false, you analyze if this variable is with value if it is null ai yes you consume the web service again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.