我正在尝试使用角度图表,但我不知道如何正确添加依赖项。我收到以下错误 Uncaught TypeError: Cannot read property 'defaults' of undefined in the angular-chart.js
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['angular', 'chart.js'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
module.exports = factory(require('angular'), require('chart.js'));
} else {
// Browser globals
factory(angular, Chart);
}
}(function (angular, Chart) {
'use strict';
Chart.defaults.global.responsive = true;
....
因为角度和图表都是未定义的。
我的要求配置是
'use strict';
require.config({
baseUrl: '/',
paths: {
'angular': '/scripts/angular',
'angular-route': '/scripts/angular-route',
'ui-bootstrap': '/scripts/ui-bootstrap-tpls-0.13.0.min',
'angular-animate': '/scripts/angular-animate.min',
'chart': '/scripts/chart',
'angular-chart': '/scripts/angular-chart',
'data-utils': '/common/data-utils',
'string-utils': '/common/string-utils',
'app': '/config/app',
'routes': '/config/routes'
},
shim: {
'app': {
deps: ['angular', 'angular-route', 'ui-bootstrap', 'data-utils', 'string-utils', 'angular-chart']
},
'angular-route': {
deps: ['angular']
},
'ui-bootstrap': {
deps: ['angular', 'angular-animate']
},
'angular-animate': {
deps: ['angular']
},
'angular-chart': {
deps: ['angular', 'chart']
}
}
});
require
(
['app'],
function(app)
{
angular.bootstrap(document, ['ngAnimate', 'ui.bootstrap', 'app']);
}
);
我的控制器是
define(['app'], function(app)
{
app.controller('homeController',
[
'$scope',
function($scope)
{
$scope.page =
{
title: 'Welcome to Easy Stitch'
};
$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]
];
}
]);
});
除了这个之外,其他所有依赖项都运行良好。请如果有人可以提供帮助。