我在一个类中创建了一个函数,稍后我将使用该函数在通过 HTTP Post 请求调用时运行一些代码。为了能够从类外部调用该函数,我认为在类外部创建一个变量并在类实例化后立即分配它就足够了。海拉斯,事实并非如此。
有没有办法从 Google Chrome 控制台访问在 Typescript 类外部声明的变量?
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.setRotationCallback = setRotation;
然后在浏览器控制台中您可以使用 window.setRotationCallback(); 调用它;
关于javascript - 从 Chrome 控制台访问变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56603175/