简体   繁体   中英

Accessing a variable from Chrome's console

I've created a function inside a class that I'll use later on to run some code when called via a HTTP Post request. To be able to call the function from the outside of the class, I thought creating a variable outside the class and assigning it as soon as the class is instantiated would suffice. Helas, it did not.

Is there a way to access a variable declared outside of a Typescript class from Google Chrome's console?

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");
    }
  }
}

you could stick the function on the global window object of the browser: window.setRotationCallback = setRotation;

then in the browser console you could call it with window.setRotationCallback();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM