![](/img/trans.png)
[英]Calling function triggered by event from an external JS file in angular component
[英]Calling external js function from Angular 5 not working
我從ts文件中調用了hello函數,但出現錯誤,例如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);
將您的JS文件包含在scripts
數組下的angular-cli.json文件中
"scripts": [
]
確保輸入正確的相對URL。 然后,您可以簡單地在ts
文件中使用它。 確保重新啟動ng serve
,如果您正在使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.