Visual Studio代码 - 在Angular中调试Promise回调

时间:2017-08-10 07:29:26

标签: angular promise visual-studio-code angular-promise

我在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()时停止程序。调用回调时,不会考虑断点。

1 个答案:

答案 0 :(得分:1)

只需添加一个回车并用花括号包装(长箭头功能表示法)。请务必添加return

return this.http.get("http://localhost:3000/api/values").toPromise()
   .then((response) => { 
      return response.json().wishes as string[]
   });