gpt4 book ai didi

javascript - 如何在 Typescript 回调中编写/转换多行 JavaScript 代码?

转载 作者:行者123 更新时间:2023-12-03 02:51:12 27 4
gpt4 key购买 nike

我有这个回调(订阅),它会在 ajax 调用的响应完成时执行。

this.workerService.isLogin()
.subscribe(res => this.isLoginSuccess = res;
console.log(this.isLoginSuccess);
this.router.navigateByUrl('/employees');
);

它是 typescript ,它相当于:

(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 新手。

最佳答案

您需要在那里创建一个 block :

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com