Visual Studio 代码 - 在 Angular 中调试 Promise 回调
Visual Studio Code - Debugging Promise Callback in Angular
我在 VS Code 中安装了以下扩展:
https://code.visualstudio.com/blogs/2016/02/23/introducing-chrome-debugger-for-vs-code
调试器可以工作,但是我无法在 Promise 回调中设置断点。例如:
getCatWishesFromBackend() : Promise<string[]> {
return this.http.get("http://localhost:3000/api/values").toPromise()
.then(response => response.json().wishes as string[]);
}
我想在代码的那部分设置断点,then() 部分里面的内容。
我该怎么做?如果我在 then() 行中设置断点,它只会在调用 this.http.get() 时停止程序。调用回调时,不考虑断点。
只需添加一个回车并将其用大括号括起来(更长的箭头函数符号)。确保添加 return
:
return this.http.get("http://localhost:3000/api/values").toPromise()
.then((response) => {
return response.json().wishes as string[]
});
我在 VS Code 中安装了以下扩展: https://code.visualstudio.com/blogs/2016/02/23/introducing-chrome-debugger-for-vs-code
调试器可以工作,但是我无法在 Promise 回调中设置断点。例如:
getCatWishesFromBackend() : Promise<string[]> {
return this.http.get("http://localhost:3000/api/values").toPromise()
.then(response => response.json().wishes as string[]);
}
我想在代码的那部分设置断点,then() 部分里面的内容。
我该怎么做?如果我在 then() 行中设置断点,它只会在调用 this.http.get() 时停止程序。调用回调时,不考虑断点。
只需添加一个回车并将其用大括号括起来(更长的箭头函数符号)。确保添加 return
:
return this.http.get("http://localhost:3000/api/values").toPromise()
.then((response) => {
return response.json().wishes as string[]
});