从角度打字稿中调用JavaScript的问题

时间:2019-04-13 18:28:52

标签: javascript angular

我正在尝试从typescript函数调用javascript函数。 这根本不起作用。

我已经在stackblitz中创建了sudo代码。请检查相同。

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

1 个答案:

答案 0 :(得分:2)

您可以将其导出到一个地方,将其导入到另一个地方。

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