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 - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -