Error: [ng: areq] Angular chart js

1

I'm doing some graphics with the Angular chart js library, I've tried with the examples I found on the page and it works correctly but when I try to make two graphics on the same page I get the following mistake

Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq?p0=BarCtrl&p1=not%20a%20function%2C%20got%20undefined

Here is my code HTML:

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title>Barra</title>
 <link href="bootstrap.css" rel="stylesheet">
</head>
<body">
 <div ng-app="app">
  <div id="container" class="container">
   <div class="row" ng-controller="BarCtrl">
    <div class="col-lg-6 col-sm-12">
     <div class="panel panel-default">
      <div class="panel-heading">Barra</div>
      <div class="panel-body">
        <canvas id="base" class="chart chart-bar"
          chart-data="data" chart-labels="labels" chart-series="series">
        </canvas> 
      </div>
     </div>
   </div>
  </div>
 </div>
</div>

<div ng-app="app1">
 <div id="container" class="container">
  <div class="row" ng-controller="BarCtrl">
   <div class="col-lg-6 col-sm-12">
    <div class="panel panel-default">
      <div class="panel-heading">Barra1</div>
      <div class="panel-body">
        <canvas id="base" class="chart chart-bar"
          chart-data="data" chart-labels="labels" chart-series="series">
        </canvas> 
      </div>
     </div>
    </div>
   </div>
 </div>
</div>

<script src="angular/angular.min.js"></script>
<script src="angular/Chart.min.js"></script>
<script src="angular/angular-chart.min.js"></script>
<script src="angular/angular-chart.js"></script>
<script src="barra.js"></script>
</body>
</html>

and this is the Js:

angular.module("app", ["chart.js"]).controller("BarCtrl", function ($scope) { $scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012']; $scope.series = ['Series A']; $scope.data = [
[65, 59, 80, 81, 56, 55, 40]]; });

angular.module("app1", ["chart.js"]).controller("BarCtrl", function ($scope {$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012']; $scope.series = ['Series A']; $scope.data = [
[65, 59, 80, 81, 56, 55, 40]]; });

Are data only test why are they the same, who believe that it can fail for me to be leaving this error?

    
asked by Santiago Muñoz 11.08.2016 в 04:10
source

1 answer

1

This is your error:

  

Error: ng: areq Bad Argument

     

Argument 'BarCtrl' is not a function, got undefined

What is happening?

The ng-controller directive is calling "BarCtrl" a driver that does not yet exist.

You fail because "barra.js" include it later with you:

<script src="barra.js"></script>

You should declare it at the beginning of your HTML before the call occurs with ng-controller.

On the other hand what you say devconcept is totally true. I recommend you take a look at the ToddMoto style guide (it's in Spanish):

link

    
answered by 22.10.2016 в 14:22