Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS Basics (1.x) Controllers and Scope Understanding Scope In Angular

U can't have that semicolon at the end of a controller if you plan on writing another controller after the initial

Cheers.

1 Answer

You still can. You just have to call module angular.module again.

angular.module('myApp', [])
  .controller('controllerName', controllerFunction);

angular.module('myApp')
  .controller('anotherControllerName', anotherControllerFucntion);

The first time you need to pass the array that will inject all your dependencies. The second time you do not, you are just getting your angular module. You will have to do something like this when you apps start to get larger and you need to break them out into different files. You might want to check out John papa's style guide. It has best practices on how you should lay out your angular app. https://github.com/johnpapa/angular-styleguide

Pierre Smith
Pierre Smith
11,842 Points

You also can assign the module to a var for simplicity like this

concatenate them like this:

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

app
.controller('controllerName', controllerFunction)
.controller('controllerName', controllerFunction);

or create them individually like this

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

app.controller('controllerName', controllerFunction);
app.controller('controllerName', controllerFunction);