1

I have put my controllers of my angular app in separate files:

This is my project structure:

Project Structure

This is bootstrap.js:

angular.module('controllers', []);

I have this in every controller file:

angular.module('controllers')
.controller('UserCtrl', ['$scope', '$state', 'auth',
    function ($scope, $state, auth) {
------

In my app.js I have this:

var app = angular.module('eva', ['ui.router','ngMaterial', 'controllers']);
-----------

At first every controller was in my app.js file, which worked perfectly. Now it doesn't load the controllers, how is this possible?

4
  • 1
    You're including the new controller files on your page right? Commented Oct 28, 2015 at 13:26
  • I only reference app.js in my index.html <script type="text/javascript" src="scripts/app.js"></script> Commented Oct 28, 2015 at 13:31
  • 2
    You have to load all the .js files for every controller and every module, as you do for app.js Commented Oct 28, 2015 at 13:32
  • 1
    Off topic (but worth mentioning): scotch.io/tutorials/… Commented Oct 28, 2015 at 13:35

2 Answers 2

1

Add the .js files for the new controllers in your HTML page and it'll work again.

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

Comments

0

Add .js file in your first loading HTML file(index.html) The orders in writing this scripts are important, too. If you have dependency they should come before modules. and controller come after module. in you case, it will be like this:

<script src="scripts/angularjs.min.js"></script>
<script src="scripts/controllers/bootstrap.js"></script>
<script src="scriptscontrollers/Appcontroller.js"></script>
// the rest of your controler script files which are part of bootstrap.js or controllers module.
<script src="scripts/app.js"></script>

Comments

Your Answer

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