从 Chrome 的控制台访问变量

Accessing a variable from Chrome's console

我在 class 中创建了一个函数,稍后我将在通过 HTTP Post 请求调用时将其用于 运行 一些代码。为了能够从 class 外部调用该函数,我认为在 class 外部创建一个变量并在实例化 class 后立即分配它就足够了。嘿,它没有。

有没有办法从 Google Chrome 的控制台访问在 Typescript class 之外声明的变量?

export var setRotationCallback;

export class SceneComponent implements OnInit {

 /* Some code around here */

  ngOnInit() 
  {
    setRotationCallback = setRotation;

    /* Some more here */

    function setRotation(jsonList: string)
    {
      console.log("Received callback");
    }
  }
}

您可以将函数粘贴到浏览器的全局 window 对象上: window.setRotationCallback = 设置旋转;

然后在浏览器控制台中,您可以使用 window.setRotationCallback();

调用它