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

Introduction to Angular Factory Question

I am stuck on something that appears to be correct and and does log the desired information to the console, yet I the code does not pass. I have researched this question and everything I have found tells me I am doing this correctly. Is there a bug in the lesson?

app.js
angular.module('treehouseCourse', [])
  .factory('Course', function() {
    return {
      title: "Intro to Angular"
    }
  });

angular.module('treehouseCourse')
.controller('MyCourseCtrl',["$scope","Course",function($scope,Course){
    console.log(Course.title);
}])
index.html
<!DOCTYPE html>
<html ng-app="treehouseCourse">
  <head>
    <title>Angular.js</title>
    <script src="js/angular.js"></script>
    <script src="app.js"></script>
  </head>
  <body ng-controller="MyCourseCtrl">
  </body>
</html>

5 Answers

Aaron Brewer
Aaron Brewer
7,939 Points
angular.module('treehouseCourse', [])
  .factory('Course', function() {
    return {
      title: 'Intro to Angular'
    }
  });

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

The above works, and is done how it should be from what I understand. You definitely did it right.

Thank you... Now if only that answer satisfied the lesson.

Aaron Brewer
Aaron Brewer
7,939 Points

Their test may just have a bug in it? Alex Vanston , can you help us out here?

Sidney Casagrande
Sidney Casagrande
7,035 Points

I'm having the same issue here. Hope we get a fast resolution for this issue, or at least some clarification.

its still not working or passing with any suggestions, i went ahead and asked my professor who came up with the same answer we have and it wouldn't pass. I checked wiht Angular up and running by O'reilly and I don't see where our problem is.

Okay, I figured it out, we're all being too clever and over thinking it :)

The question says "Within the controller, log the injected factory to the console using console.log.", and we were all logging the title attribute.

The correct answer is:

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