0

In my Angular6 component, I am embedding an iframe. The javascript code inside the iframe needed me to declare a global object with a specific name ("API Callback") so that it can invoke different methods on the global object. Is it possible to create a global object like this as we used to do in JavaScript?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Rajeev
  • 23
  • 7

1 Answers1

0

If you want to create a global object, then just attach it to the window object.

window.property = `I'm global`;

console.log(property);
Guerric P
  • 30,447
  • 6
  • 48
  • 86
  • thanks for the answer. I am using Angular6, so the below code worked for me. Got it from (https://stackoverflow.com/a/13480754/5841523) window['propertyName'] = MyTypeScriptCallbackObject; – Rajeev Sep 28 '18 at 02:51
  • you mean Typescript complained about the `window.property` syntax? – Guerric P Sep 28 '18 at 07:00