简体   繁体   English

angular.module('myapp',['chart.js'])未捕获的错误:[$ injector:modulerr]

[英]angular.module('myapp',['chart.js']) Uncaught Error: [$injector:modulerr]

I am new at Working with Angular.JS. 我是使用Angular.JS的新手。 Want to make chart using chart.js 想要使用chart.js制作图表

I've installed chart.js with 我已经安装了chart.js

npm install angular-chart.js --save npm install angular-chart.js-保存

.state('index.dashboard', {
            url: "/dashboard",
            templateUrl: "modules/dashboard/dashboard.html",
            controller: 'dashboardController',
            data: { pageTitle: 'Dashboard' },
            resolve: {
                loadPlugin: function($ocLazyLoad) {
                    return $ocLazyLoad.load([{
                            serie: true,
                            files: ['css/plugins/c3/c3.min.css', 'js/plugins/chartJs/Chart.min.js', 'js/plugins/d3/d3.min.js', 'js/plugins/c3/c3.min.js']
                        }, {
                            serie: true,
                            name: 'gridshore.c3js.chart',
                            files: ['js/plugins/c3/c3-angular.min.js']
                        }, {
                            serie: true,
                            name: 'angular-dygraphs',
                            files: ['bower_components/angular-dygraphs/src/angular-dygraphs.js']
                        }, {
                            serie: true,
                            files: ['css/style_2.css', 'js/plugins/highcharts/highstock.src.js']
                        }, {
                            serie: true,
                            name: 'highcharts-ng',
                            files: ['js/plugins/highcharts/highcharts-ng.js']
                        },{
                            serie: true,
                            name:"chart.js",
                            files:['js/plugins/chartJs/angular-chart.js']
                        },
                        //               {
                        // name: 'chart.js',
                        //                   files: ['bower_components/Chart.Zoom.js/src/chart.zoom.js']
                        // //               },
                        //               {
                        //                   name: 'angles',
                        //                   files: ['js/plugins/chartJs/angles.js']
                        //               },
                        {
                            files: ['css/plugins/jsTree/style.min.css', 'js/plugins/jsTree/jstree.min.js', 'css/plugins/iCheck/custom.css', 'js/plugins/iCheck/icheck.min.js']
                        }, {
                            name: 'ngJsTree',
                            files: ['js/plugins/jsTree/ngJsTree.min.js']
                        }, {
                            name: 'cgNotify',
                            files: ['css/plugins/angular-notify/angular-notify.min.css', 'js/plugins/angular-notify/angular-notify.min.js']
                        }
                    ]);
                },
                authenticated: authenticated
            }
        })

and now i am adding that to my controller 现在我将其添加到我的控制器中

angular.module('inspinia',['chart.js'])
.controller('dashboardController', ['$rootScope', '$scope', '$http',  function($rootScope, $scope, $http) {
var a = 0;
}]);  

I've tried with 我尝试过

angular.module('inspinia')
.controller('dashboardController', ['$rootScope', '$scope', '$http','chart.js',  function($rootScope, $scope, $http) {
var a = 0;
}]);

but getting same error of 但得到相同的错误

Uncaught Error: [$injector:modulerr] 未捕获的错误:[$ injector:modulerr]

Please help me with correct way Thanks in advcance 请以正确的方式帮助我,谢谢

You dont have to inject chart.js to the controller, 您不必将chart.js注入控制器,

change it as, 改成

angular.module('inspinia')
.controller('dashboardController', ['$rootScope', '$scope', '$http',  function($rootScope, $scope, $http) {
var a = 0;
}]);

DEMO 演示

  1. Include the angular-chart.js script tag in your index.html , after angular.js , as suggested by Tushar. 根据Tushar的建议,在angular.js之后的index.html包含angular-chart.js脚本标签。

  2. Add chart.js as a module dependency when initializing your inspinia module, just as you did in your first code snippet. 添加chart.js作为一个模块依赖你的初始化时inspinia模块,就像你在你的第一个代码片断一样。

  3. Use the directives provided by the module, there's no need to inject anything in your controllers. 使用模块提供的指令,无需在控制器中注入任何东西。

be sure to import it in app.js like: 确保将其导入app.js中,如下所示:

"use strict";

angular.module("yourmodulename",
[
    "ui.router",
     "chart.js" //<-- import it
]);

And the use it in your controller ... Or if you use OcLazy (for lazy loading ) something like: 并在控制器中使用它...或者,如果您使用OcLazy(用于延迟加载),则如下所示:

.state("profile.index", {
                url: "/profile",
                templateUrl: "/app/view/template/profilo/profile.html",
                controller: "ProfileController",
                controllerAs: "profileCtrl",
                resolve: {
                    loadPlugin: function ($ocLazyLoad) {
                        return $ocLazyLoad.load([

                            {
                                name: "chart.js",
                                serie: true,
                                files: ["/app/view/assets/lib/bower/Chart.js/Chart.min.js", "/app/view/assets/lib/bower/angular-chart.js/dist/angular-chart.js", "/app/view/assets/lib/bower/angular-chart.js/dist/angular-chart.css"]
                            }
                        ]);
                    }

                }
            })

I have got the same problem but different pages, so i needed to add EVERY SIGLE PAGE code snippet and error is gone. 我遇到了相同的问题,但页面不同,因此我需要添加每个轻松页面代码段,错误消失了。 However, I didn't understand the reason whey i needed to add. 但是,我不明白我需要添加乳清的原因。

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

Putting 推杆

<script src="lib/chart.js/dist/Chart.min.js"></script>

before 之前

<script src="lib/chart.js/dist/angular-chart.js"></script>

solved my problem 解决了我的问题

And I've removed 我已经删除了

('myapp',['chart.js']) ('myapp',['chart.js'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的错误:[$injector:modulerr] 错误:[$injector:nomod] 模块“chart.js”不可用 - Uncaught Error: [$injector:modulerr] Error: [$injector:nomod] Module 'chart.js' is not available 错误:$ injector:modulerr模块错误-chart.js - Error: $injector:modulerr Module Error - chart.js Angular JS:未捕获的错误:[$ injector:modulerr]无法实例化模块 - Angular JS : Uncaught Error: [$injector:modulerr] Failed to instantiate module 未捕获的错误:[$ injector:modulerr]由于以下原因而无法实例化模块myApp:错误:[$ injector:modulerr] - Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:modulerr] 未捕获的错误:[$injector:modulerr] 与 Angular JS - Uncaught Error: [$injector:modulerr] with Angular JS 在角度js中出现未捕获的错误:[$ injector:modulerr] - getting Uncaught Error: [$injector:modulerr] in angular js Angular JS-未捕获的错误:[$ injector:modulerr]。 - Angular JS - Uncaught Error: [$injector:modulerr]. 未捕获的错误:[$ injector:modulerr] Angular js中的ngRoute - Uncaught Error: [$injector:modulerr] ngRoute in angular js Angular JS 未捕获错误:[$injector:modulerr] - Angular JS Uncaught Error: [$injector:modulerr] 角度错误[$ injector:modulerr]无法实例化模块myApp - Angular error [$injector:modulerr] Failed to instantiate module myApp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM