Reputation: 383
i am trying to use angular-chart but i couldn't figure how to add dependencies correctly. i am getting following error 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;
....
because both angular and chart are undefined.
my require config is
'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']);
}
);
my controller is
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]
];
}
]);
});
every other dependency is working fine except for this one. please if anyone can help.
Upvotes: 5
Views: 1537
Reputation: 1123
After installing angular-chart with bower, I had to change
define(['angular', 'chart'], factory);
into
define(['angular', 'Chart'], factory)
because Charts.js will export Chart and not chart.
Upvotes: 0
Reputation: 33
you can modify the angular-chart.js:
chart.js => chart,
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module
define(['angular', 'chart'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
module.exports = factory(require('angular'), require('chart'));
} else {
// Browser globals
factory(angular, Chart);
}
Upvotes: 2
Reputation: 383
I figure that I have to correct the dependency in my require config file and after that it is working fine.
require
(
['app'],
function(app)
{
angular.bootstrap(document, ['ngAnimate', 'ui.bootstrap', 'chart.js', 'app']);
}
);
Upvotes: 2
Reputation: 40308
It seems angular-chart expects the Chart.js module to be called "chart.js":
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['angular', 'chart.js'], factory);
} ...
Chart.js itself uses anonymous define (ref), so it is up to you to name it. You are naming it "chart":
require.config({
paths: {
...
'chart': '/scripts/chart',
...
So, just call it 'chart.js'
in the paths
configuration!
Upvotes: 0