I called hello function from ts file but I got error like hello is not defined.
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);
Include your JS file in angular-cli.json file under scripts
array
"scripts": [
]
make sure to put the correct relative URL. And then you can simply use it in your ts
file. Make sure to restart ng serve
if you are using it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.