javascript - Asynchronous functions in Typescript/Angular 2 -


i having trouble when nesting 2 functions. second function executing before first 1 finished. have 2 methods:

dologin() {     return this.authservice.dologin(); }  tologin(){     this.router.navigatebyurl("/secure"); } 

the first function dologin() takes awhile because of service. how can make second function, tologin() execute after dologin() has finished , returns true (using promises, or callbacks)?

i new angular , javascript, please thorough in explanation.

cheers!

by using promise

dologin() {     return this.authservice.dologin().then(function(result){         tologin();     }); } 

you need return promise in this.authservice.dologin()


Comments

Popular posts from this blog

php - Autoloader issue not returning Class -

java - How to put two numbers separated by a space into two different arrays -

python - matplotlib equivalent for Ubuntu servers with no GUI? -