I have an Angular 6 app with Live Chat for Angular installed.
I'm trying to use the Live Chat Javascript API library to hide the default floating button.
If I run LC_API.hide_chat_window();
in the browser developer console, it works.
However, if I add that code to the Angular component .ts file, it does not work (Because it does have access to the global variable LC_API
).
How can I get access to that global variable?
You could inject window into your component and then access the variable on there as traditionally in JS that is where global variables reside. See also https://stackoverflow.com/a/40222547/1260204
You can shape the expected interface in the constructor for type safety.
constructor(@Inject("windowObject") private window: {LC_API:any})