Search code examples
javascriptangulartypescriptapi-design

How to make my TypeScript object available to a third party Javascript


I have an Angular application and need to create an API for a third party javascript that will be added dynamically.

public class MyApi{
   public callSomeFunction():void{...}
   public getSomeValue():any {...}   
}
var publicApi = new MyApi();

How do I get the publicApi object into javascripts global scope?


Solution

  • You can add it to the global object of the client-side which is window object.

    window.publicApi = new MyApi();