Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Angular: What does this error in the console mean?

Error: [ng:areq] http://errors.angularjs.org/1.5.0/ng/areq?p0=aboutController&p1=not%20aNaNunction%2C%20got%20undefined
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:6:416
    at sb (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:23:63)
    at Sa (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:23:150)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:86:318
    at A.link (http://port-80-x81rup9szl.treehouse-app.com/vendor/angular-route.min.js:7:274)
    at ka (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:79:16)
    at u (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:66:326)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:58:136)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js:57:279

app.js

var app = angular.module('appName', ['ngRoute']);

app.config(function($routeProvider) {
  $routeProvider
  .when('/', {
    controller: 'homeController',
    templateUrl: '../views/home.html'
  })
  .when('/about', {
    controller: 'aboutController',
    templateUrl: '../views/about.html'
  })
  .otherwise({
    redirectTo: '/'
  });  
});

Controller #1

app.controller('aboutController', ['$scope', function($scope) {

}]);

Controller #2

app.controller('homeController', ['$scope', function($scope) {

}]);

index.html

<!doctype html>
<html>
  <head>
    <title>Angular App</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/app.css">
  </head>
  <body ng-app="appName">

    <div class="container">
      <div class="row">
        <div ng-view></div>
      </div>
    </div>

    <!-- angular -->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
    <script src="vendor/angular-route.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.js"></script>
    <script src="js/app.js"></script>
    <!-- bootstrap -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- controllers -->
    <script src="js/controllers/homeController.js"></script>
    <!-- directives -->

    <!-- services -->
    <script src="js/services/data.js"></script>
  </body>
</html>

1 Answer

Aidan Pine
Aidan Pine
9,210 Points

It looks like it has something to do with your angular.module. Perhaps you have it defined incorrectly, or defined in two places, or you have two modules with the same name. Could also be that you created a new module and didn't inject it into your application. Can you post the code?

https://docs.angularjs.org/error/ng/areq https://stackoverflow.com/questions/21673404/error-ngareq-from-angular-controller

Yes i can. One moment...

Aidan Pine
Aidan Pine
9,210 Points

Have you included ng-app="appName" in index.html somewhere?