【问题标题】:Visual Studio Code - Debugging Promise Callback in AngularVisual Studio Code - 在 Angular 中调试 Promise 回调
【发布时间】:2018-08-24 04:09:27
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    只需添加一个输入并将其包裹在花括号中(更长的箭头函数符号)。确保添加return:

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

    【讨论】:

      猜你喜欢
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2018-08-18
      • 2017-12-18
      相关资源
      最近更新 更多