0

I am new to Angular.js and am having a issue with setting the controllers. In the browser, I am getting a error 'uncaught referenceError: myappApp is not defined' for myappApp.controller('HomeController'...). I am not sure why because the ng-app='myappApp' is set and works successfully and it also is set in angular.module('myappApp'...). Otherwise, everything loads ok.

one@localhost ~/angular.js-project/myapp/app $ cat scripts/app.js 
'use strict';

angular
  .module('myappApp', [
    'ngCookies', 'ngRoute'
  ]).config(function($routeProvider) {
      $routeProvider.when('/home', {
      templateUrl: 'views/home.html',
      controller: 'HomeController'
      });

      $routeProvider.when('/first', {
      templateUrl: 'views/first.html',
      controller: 'FirstController'
      });



      $routeProvider.otherwise({ redirectTo: '/home'});
  });


myappApp.controller('HomeController', function($scope, $location, $anchorScroll) {
    $scope.scrollTo = function(id) {
    $location.hash(id);
    $anchorScroll();
    }
});

myappApp.controller('FirstController', function($scope, $location, $anchorScroll) {
    $scope.scrollTo = function(id) {
    $location.hash(id);
    $anchorScroll();
    }
});

1 Answer 1

1

Either do:

var myappApp = angular
  .module('myappApp', [
    'ngCookies', 'ngRoute'
  ])

or

angular.module('myappApp').controller(...)

When you do myappApp.controller that is looking for a myappApp variable, which isn't defined anywhere. So either assign the result of angular.module to it or keep using angular.module as in above.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.