gpt4 book ai didi

javascript - Angular Chart JS 错误 angular-master.js :114 Error: [$injector:unpr]

转载 作者:行者123 更新时间:2023-12-03 05:21:04 25 4
gpt4 key购买 nike

我正在使用 Angular.JS 开发 Chart.js,我的 Angular 应用程序如下所示

angular.module('inspinia').controller('dashboardController', ['$rootScope', '$scope', '$http','chart.js', function($rootScope, $scope, $http) {
console.log("123");
$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
$scope.series = ['Series A', 'Series B'];
$scope.data = [[65, 59, 80, 81, 56, 55, 40],[28, 48, 40, 19, 86, 27, 90]];

我的 HTML 代码如下所示

<div class="text-center">
<canvas id="bar" class="chart chart-bar"chart-data="data" chart-labels="labels"> chart-series="series"
</canvas>
</div>

我收到两个错误

Uncaught TypeError: Cannot set property 'mode' of undefined

其他的是

Error: [$injector:unpr]

http://errors.angularjs.org/1.5.0/$injector/unpr?p0=chart.jsProvider%20%3C-hart.js%20%3C-%dashboardController

请帮我解决这个问题

提前致谢

最佳答案

确保您正确引用了库,

工作演示

(function(angular) {
'use strict';
angular.module('myApp', ['chart.js'])

.controller('myController', [function() {
var ctrl = this;
ctrl.socialChart = {
type: 'bar',
labels: ['2006', '2007', '2008', '2009', '2010', '2011', '2012'],
series: ['Series A', 'Series B'],
colors: ['#ED402A', '#F0AB05', '#A0B421', '#00A39F'],
data : [[65, 59, 80, 81, 56, 55, 40],[28, 48, 40, 19, 86, 27, 90] ]
}

}]);

})(window.angular);
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<title>Multi Slot Transclude</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script> <script src="app.js"></script>
</head>

<body ng-app="myApp" ng-controller="myController as ctrl">
<canvas id="outreach" class="chart chart-bar"
chart-labels="ctrl.socialChart.labels"
chart-data="ctrl.socialChart.data"
chart-series="ctrl.socialChart.series"
chart-colors="ctrl.socialChart.colors"
chart-options="ctrl.socialChart.options"></canvas>
</body>

</html>

关于javascript - Angular Chart JS 错误 angular-master.js :114 Error: [$injector:unpr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41377849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com