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 Creating controllers in Angular

Hamed Ali
Hamed Ali
5,626 Points

need help with creating a controller

Create new controller called "coolCtrl"

Im not sure what I am doing wrong here

app.js
angular.module('foobar', []);
.controller('coolCtrl', function());

2 Answers

Hi Hamed,

There are a few ways to define a controller in Angular, but I believe the challenge would like it defined this way:

var myApp = angular.module("foobar", []);

myApp.controller('coolCtrl', ['$scope', function($scope) {
}]);
Hamed Ali
Hamed Ali
5,626 Points

thx Paul,

I used this and found that it worked also:

angular.module('foobar', []) .controller('coolCtrl', function($scope) {

});

I like that style much more(most of my Angular stuff looks like that too). Glad it all worked!