调用Angular 5的外部JS功能不起作用



我从ts文件中调用了Hello函数,但是我有错误的错误。

hello.js

function hello() {
    alert("Hello.......!");
}

index.html

<script src="./assets/js/hello.js"></script>

component.ts

declare var hello: any;
// calling on load
let result = hello();
console.log(result);

scripts array下,将您的js文件包括在angular-cli.json文件中

"scripts": [
]

确保放置正确的相对URL。然后,您只需在ts文件中使用它即可。如果您使用的话,请确保重新启动ng serve

最新更新