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
Post a Comment