0

i try to write an angular app using best code practice and i got to this:

index.html file contain :

<!DOCTYPE html>
 <html ng-app='hrsApp'>
 <head>
<title>Hrs app</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body ng-controller="homeCtrl">
<div class='container'>
    <div ng-view></div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-route.min.js"></script>
<script src='app.js'></script>
<script src='js/controllers/homeCtrl.js'></script>
<script src='js/controllers/avCtrl.js'></script>
</body>
</html>

Main file: app.js:

angular.module('home', []);
angular.module('av', []);

// Declare app level module which depends on filters, and services
angular.module('hrsApp', [
'hrsApp.controllers',
'hrsApp.services',
'hrsApp.directives',
'hrsApp.filters',

// AngularJS
'ngRoute',

// All modules are being loaded here but EMPTY - they will be filled with controllers and      functionality
'home',
'av'
]);

// configure our routes
angular.module('hrsApp').config([
'$routeProvider',
function ($routeProvider) {
    'use strict';

    $routeProvider
        // route for the home page
        .when('/', {
            templateUrl: 'views/home.html',
            controller: 'homeCtrl'
        })

        // route for the about page
        .when('/av', {
            templateUrl: 'views/av.html',
            controller: 'avCtrl'
        })

        // route for the contact page
        .otherwise({
            redirectTo: '/'
        });
}
]);

Then i added the home controller:

/*global angular*/

angular.module('home').controller('homeCtrl', [
 '$scope',
function ($scope) {
    'use strict';

    $scope._init = function () {
        $scope.message = "welcome to Home Ctrl";
    };

    // DESTRUCTOR
    $scope.$on('$destroy', function () {

    });

    // Run constructor
    $scope._init();

    $scope.log('info', '[HomeCtrl] initialized');
}
]);

and home template that for the moment contain only a binding to the message variable:

<div>{{message}}</div>

When i try to run the application i got : Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.0/$injector/modulerr?p0=hrsApp&p1=Error%3A%…googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0%2Fangular.min.js%3A18%3A3) angular.js:38

Any idea what i do wrong?

7
  • 2
    Can you put the full error URL? (open on the browser and then ctrlc ctrlv) Commented Oct 26, 2014 at 15:19
  • just include app.js after homeCtrl.js and avCtrl.js Commented Oct 26, 2014 at 15:23
  • where you define next modules: 'hrsApp.controllers', 'hrsApp.services', 'hrsApp.directives', 'hrsApp.filters' Commented Oct 26, 2014 at 15:29
  • i did include app.js after homeCtrl and i got 3 errors injector.nomod ... i didn't created yet services directive, filter but even if i commenyt them i still got initial p[roblem ... Commented Oct 26, 2014 at 15:39
  • 1
    something like angular.module('hrsApp.controllers',[]); angular.module('hrsApp.services',[]); angular.module('hrsApp.directives',[]); angular.module('hrsApp.filters',[]); Commented Oct 26, 2014 at 16:00

1 Answer 1

1

From your code I can see that you have injected modules that you did not declared.

in order todo so you must add the following lines to your code:

angular.module('hrsApp.controllers',[]);
angular.module('hrsApp.services',[]);
angular.module('hrsApp.directives',[]);
angular.module('hrsApp.filters',[]);
Sign up to request clarification or add additional context in comments.

1 Comment

you are right thanks but seems unethical to vote your question when @Grundy already give the right answer before you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.