簡體   English   中英

從Angular 5調用外部js函數不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM