Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript AngularJS Services and Dependencies Services: Requiring factories

Chris Shaw
Chris Shaw
26,650 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

Kyle Meyer
Kyle Meyer
5,447 Points

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,650 Points

Thanks Kyle,

All is working well now :stuck_out_tongue:

Kyle Meyer
Kyle Meyer
5,447 Points

Glad to hear it!

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

Chris Shaw
Chris Shaw
26,650 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.