-5

I have a plain old .js file that draws svg on my Angular component. I have some events in that file and I want to call functions defined in my component code from that .js file.

I haven't found any solution to this problem? Is this achievable? If yes how?

Thank you.

Muhammad Ahsan
  • 608
  • 15
  • 28
  • Have a look there: https://stackoverflow.com/questions/61777225/calling-an-angular-component-method-from-classic-html/61778035#61778035 – David May 29 '20 at 08:46

1 Answers1

2

I think that you can create a custom event in javascript and "listen" in your Angular app, but I'm not prety sure if this work

To create a custom event in javascript see this link

var event = new Event('build',{ data: 'hello word' });
// Dispatch the event.
window.dispatchEvent(event);

To listen the event in Angular, use fromEvent rxjs

ngOnInit()
{
    fromEvent(window,'build').subscribe(event=>{
       console.log(event.data)
    })
}
Eliseo
  • 50,109
  • 4
  • 29
  • 67