score:0

Accepted answer

the problem is that you're not awaiting for the http call to return the actual data. change the method getsimulation to look like this:

async getsimulation(id: string): promise<void> {
  try {
    this.currentsimulation = await this.controllerservice.get(id).topromise();
    console.log('current simulation data retrieved successfully', this.currentsimulation);
  } catch (error) {
    console.error('error retrieving current simulation', error);
  }
}

and then also do this adjustments to ngoninit().

async ngoninit(): promise<void> {
  var id = this.route.snapshot.params['id'];
  await this.getsimulation(id);
  .............................
}

this should do the trick.


by the way, i don't know what version of angular you're using, that's why i used .topromise() for casting from observable to promise. however on the recent versions of angular (iirc angular 11+), lastvaluefrom is the one to use, since .topromise() was deprecated and will be removed sooner than later.

so getsimulation would ideally look like this:

async getsimulation(id: string): promise<void> {
  try {
    this.currentsimulation = await lastvaluefrom(this.controllerservice.get(id));
    console.log('current simulation data retrieved successfully', this.currentsimulation);
  } catch (error) {
    console.error('error retrieving current simulation', error);
  }
}

Related Query

More Query from same tag