I am trying to get Angular working with Google Charts via the Google Charts Angular Directive Module but can't seem to get it to work. I get this error:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
Angular Code:
var myApp = angular.module("myApp", ['googlechart']);
myApp.factory("DataService", ["$http", function ($http){
var getData = function(callback){
var url = 'api-url-returns-json';
$http.get(url).success( function(response) {
callback(response);
});
}
return {
getDashboardData: getData
}
}]);
myApp.controller("dashboardController", ["$scope", "DataService", "ClockProvider", function ($scope, DataService, ClockProvider){
DataService.getDashboardData(function(data){
$scope.dashboard = data;
});
var intervals = ["0", "30"];
ClockProvider.run(intervals, function(){
DataService.getDashboardData(function(data){
$scope.dashboard = data;
});
});
}]);
angular.module("myApp", ["googlechart", "googlechart-docs"]).controller("GenericChartCtrl", function ($scope) {
$scope.chartObject = {};
$scope.chartObject.type = "BarChart";
$scope.onions = [
{v: "Onions"},
{v: 3},
];
$scope.chartObject.data = {"cols": [
{id: "t", label: "Topping", type: "string"},
{id: "s", label: "Slices", type: "number"}
], "rows": [
{c: [
{v: "Mushrooms"},
{v: 3},
]},
{c: $scope.onions}
{c: [
{v: "Olives"},
{v: 31}
]},
{c: [
{v: "Zucchini"},
{v: 1},
]},
{c: [
{v: "Pepperoni"},
{v: 2},
]}
]};
$scope.chartObject.options = {
'title': 'How Much Pizza I Ate Last Night'
};
});
HTML:
<html ng-app="myApp">
<head>
<script src="ng-google-chart.js"></script>
<script src="app.js"></script>
</head>
<body>
<div class="side front" ng-controller="GenericChartCtrl">
<div google-chart chart="chartObject"">
</div>
</div>
</body>
</html>
<script>tag :)