簡體   English   中英

如何將“ Chart.js”注入我的模塊?

[英]How to inject “Chart.js” to my module?

這是我的HTML。 我給出了這樣的路徑:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">

     <script type="text/javascript" href="/node_modules/angular-chart.js/dist/angular-chart.min.js"></script>
    <script type="text/javascript" href="/node_modules/chart.js/dist/Chart.min.js"></script>


    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" type="text/css" href="app/components/root/root.css">
    <link rel="stylesheet" type="text/css" href="app/components/imgComponent/imgComponent.css">
    <link rel="stylesheet" type="text/css" href="app/components/typesComponent/typesComponent.css">
    <link rel="stylesheet" type="text/css" href="app/components/sourceComponent/sourceComponent.css">
    <link rel="stylesheet" type="text/css" href="app/components/severitiesComponent/severitiesComponent.css">
    <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />

</head>
<body ng-app="appModule">
    <app-root></app-root>
</body>
</html>

在我的腳本中,我寫道:

'use strict';

const appModule = angular.module('appModule',["chart.js"]);

appModule.component('appSeveritiesComponent', {
    templateUrl: '/app/components/severitiesComponent/severitiesComponent.html',
    controller: severitiesComponentController,
    bindings: {
    }
});

severitiesComponentController.$inject = [];

function severitiesComponentController() {
}

當我在我的應用程序中使用它給錯誤

未捕獲的錯誤:[$ injector:modulerr]

如何解決這個錯誤?

您缺少angular.js的參考

在上面添加angular.js的參考

  <script type="text/javascript" href="/node_modules/angular-chart.js/dist/angular-chart.min.js"></script>
    <script type="text/javascript" href="/node_modules/chart.js/dist/Chart.min.js"></script>

腳本的順序很重要。 如果查看angular-chart.js的“ 安裝”部分,您將看到以下順序:

<script src="node_modules/chart.js/Chart.min.js"></script>
<script src="node_modules/angular-chart.js/dist/angular-chart.min.js"></script>

Chart.js應該 angular-chart.js 之前

此外,您還需要在這兩個腳本之前插入angular.js腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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