0
두 함수를 중첩 할 때 문제가 있습니다. 두 번째 함수는 첫 번째 함수가 완료되기 전에 실행 중입니다. I는 두 가지 방법이 있습니다)비동기 함수 (Typescript/Angular 2)
doLogin() {
return this.authService.doLogin();
}
toLogin(){
this.router.navigateByUrl("/secure");
}
제 1 함수를 doLogin (잠시 인해 서비스의 걸린다. doLogin()이 완료되고 true (약속 또는 콜백 사용)를 반환 한 후에 만 toLogin()이 실행되는 두 번째 함수를 만들 수 있습니까?
나는 각도와 자바 스크립트에 익숙하지 않으므로 설명을 철저히하십시오.
건배! 약속
당신이 this.authService.doLogin에 약속을 반환해야doLogin() {
return this.authService.doLogin().then(function(result){
toLogin();
});
}
를 사용하여