As @VLAZ points out, you need a arrow function (to "close over" the correct this-scope, eg.:
setTimeout(() => {
this.clearGroups();
this.prepareRow();
this.prepareGroups();
}, 2000);
I would however suggest that you reconsider your solution, what about the users that has very poor internet connectivity, where the result could take more than 2 seconds "to arrive", and do you want to penalize people with a fast connection to wait the 2 seconds (for the update to appear)?
If your data arrives as a promise, consider using async / await:
await getData();
this.clearGroups();
this.prepareRow();
this.prepareGroups();
(please notice that this will only work if done from an async function, else use as traditional Promise with .then(() => ...))
or as an Observable:
getData().pipe(first()).subscribe(() => {
this.clearGroups();
this.prepareRow();
this.prepareGroups();
});
async/awaitto ensure these are called after the reload. Otherwise, you get into a dangerous territory when the calls might be out of sync.setTimeout, you need an arrow function, otherwise the value ofthiswill be incorrect.setTimeout(). There is a reason HTTP calls are asynchronous. Because you don't know when they will respond. If you're using AngularHttpClientto make the calls, then you need to place the statements that depend on it inside the subscription. If there are multiple independent calls, useforkJointo combine them. If they are dependent on each other, map them usingswitchMap.