I am trying to call javascript function from the typescript function. This is not working at all.

I have created sudo code in stackblitz. Please check the same.

https://stackblitz.com/edit/angular-nullyo

1 Answers

2
Stavm On Best Solutions

You can export it at one place, import it at another.

hello.js

export function hello() {
  console.log('hello world');
}

app.component.ts

import { hello } from '../external/hello.js';

@Component({
  // ...
})
export class AppComponent  {   
  buttonClick() {
    console.log('btn click called. 1.');
    hello();
    console.log('btn click called. 2.');
  }
}

DEMO