我有这个回调(订阅),它会在ajax调用的响应完成时执行。
this.workerService.isLogin()
.subscribe(res => this.isLoginSuccess = res;
console.log(this.isLoginSuccess);
this.router.navigateByUrl('/employees');
);
它是打字稿,它等效于:
(function (res) { return _this.isLoginSuccess = res; });
console.log(this.isLoginSuccess);
this.router.navigateByUrl('/employees');
我希望翻译是:
(function (res) {
return _this.isLoginSuccess = res;
console.log(this.isLoginSuccess);
this.router.navigateByUrl('/employees');
});
我是Typescript的新手。
最佳答案
您需要在此处创建一个块:
this.workerService.isLogin()
.subscribe(res => {
this.isLoginSuccess = res;
console.log(this.isLoginSuccess);
this.router.navigateByUrl('/employees');
});
关于javascript - 如何在Typescript回调中编写/转换多行JavaScript代码?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47850051/