Function executing before the response of my request

0

In a modal I have a form with data that can be edited. If the user confirms the update the data is updated and then it will be forwarding the new page. But in this new page the information that appears is still old (before the update). If I give an F5 the new information will appear.

Information before updating

Newinformation

InformationthatappearsfirstwhenIconfirmtheupdate.

AftertheF5

Follow the code below:

updateClonedQuote(): void {
    this.canDeactivate = false
    const updateQuote = this.cloneQuoteForm.getRawValue() as ClonedQuoteValue
    this.quoteService.updateQuote(updateQuote, this.dataClonedQuote.id)
      .subscribe(
        () => {},
        (err) => console.log(err),
        () => {
          this.modalService.dismissAll()
          this.route.navigate(['quotes-abertas/', this.dataClonedQuote.id])
        }
      )
  }
    
asked by anonymous 03.12.2018 / 18:20

1 answer

1

Verifies that the browser is not caching the request to the server. If it is, it will always return the same data, because the browser thinks you are asking for exactly the same information.

In case of this, you can add a random value to the end of the url for the browser to find that it is always a new request, such as by exampo

// random number between 0 and 999
const version = Math.floor(Math.random() * 1000);
const requestEndpoint = 'https://endpoint.com/api/quotes?=v${version}'

In this way the request is always diference.

    
03.12.2018 / 19:51