I'm a beginner in Angular.js and facing an issue with setting up the controllers. When I try to run my code in the browser, I encounter an error
'uncaught referenceError: myappApp is not defined'
for myappApp.controller('HomeController'...)
. It's puzzling because ng-app='myappApp'
is properly set and functioning, as well as being defined in angular.module('myappApp'...)
. Everything else seems to load fine.
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();
}
});