new here so apologies if I don't lay this out as you'd expect.
So I'm submitting my reactive form data to the server (mongodb database). I then want to route to a new path passing the ID element that the database returns to the front end as a param in the URL.
This is what I have in the submit function so far:
  onsubmit(){
    let opdata = null;
    this.location.saveOpnote(this.form.value)
    .subscribe(response => {
      opdata = response
      console.log(response)
    })
    this.route.navigate(['/opnotes/mopsdisplay', opdata._id])
  }
So data saves perfectly and backend returns the _id of the new entry. Browser complains:
ERROR TypeError: Cannot read property '_id' of null
My understanding is the browser is looking at this before the asynchronous part of saving to the server is completed and the _id is available.
How do I get round this?
Many thanks.
 
     
    