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 Services and Dependencies Services: Requiring factories

Chris Shaw
Chris Shaw
26,676 Points

Broken AngularJS challenge

The challenge appears to be broken as the errors received are contradicting against what the challenge is expecting.

First error

Bummer! You need to use array notation to require the factory. The first array element should be the factory name, 'Course'.

angular.module('treehouseCourse')
  .controller('MyCourseCtrl', ['$scope', 'Course', function($scope, Course) {
    console.log(Course);
  }]);

Second error

Bummer! When you require the factory using array notation, the second array element should be a function.

angular.module('treehouseCourse')
  .controller('MyCourseCtrl', ['Course', '$scope', function(Course, $scope) {
    console.log(Course);
  }]);

As you can see both examples above are valid, it simply appears as those the parser is broken.

/cc Alex Vanston

2 Answers

Hey Chris Upjohn

You're totally right! Thanks for catching this bug. I updated the code challenge to properly assert that $scope is required in the controller and made the ordering of Course and $scope unimportant, since that only influences the order of the arguments passed to the function. Both of your examples now pass as expected.

Thanks again, and sorry for the confusion!

:zap:

Chris Shaw
Chris Shaw
26,676 Points

Thanks Kyle,

All is working well now :stuck_out_tongue:

Glad to hear it!

He didn't mention to include $scope, just remove that and it works.

Chris Shaw
Chris Shaw
26,676 Points

That makes sense but AngularJS controllers should always have $scope declared, if the controller doesn't that leaves all the previous videos with contradicting information, it's also stated as part of the official AngularJS documentation.

https://docs.angularjs.org/guide/controller

Also the second example should have passed since Course is still the first parameter of the function, to me that's broken.