1
How to make a method to be executed only after the completion of another method? I understand that in Angular we treat asynchronously, that is, a line of code does not necessarily wait for the completion of the previous one to be executed, nor do I want to use a setTimeout() forcing a method to wait a certain time to be executed. Below I have the following code:
intervalo: number = 10;
resultado: number = 0;
constructor() { }
ngOnInit() {
}
somarValoresIntervalo() {
for(let x = 1; x < this.intervalo; x++) {
this.resultado += x;
}
imprimirResultadoMultiplicado(){
this.somarValoresIntervalo();
console.log(this.resultado*10);
}
}
I want the console.log() in the print methodResulted() to be executed only after the previous line has been completed (no matter how long it takes). Is there any way to resolve this through Obsevable,?
Good Daniel, I’ll do it this way.
– Gonzaga Neto
I used the first scenario, it worked perfectly.
– Gonzaga Neto