[英]How to import an external javascript library in angular?
我正在嘗試導入諸如popper,jquery和chart.js之類的庫以在有角度的項目中使用。
我使用cli下載了它們,並在我的index.html
和angular.json
文件中引用了它們。
index.html
<head>
...
<script src="node_modules/chart.js/dist/Chart.js"></script>
</head>
angular.json
...
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.css",
"node_modules/font-awesome/css/font-awesome.css",
"src/styles.css"
],
"scripts": [
"node_modules/chart.js/dist/Chart.js"
]
...
出現的錯誤信息是
The resource from “http://localhost:4200/node_modules/chart.js/dist/Chart.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)
以Chart.js為例:
npm install --save chart.js
npm install --save-dev @types/chart.js
然后在您的組件中:
import * as Chart from 'chart.js'
...
const chart = new Chart(...)
無需觸摸index.html
或將任何內容放入您的angular.json
腳本中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.