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 trialSidney Casagrande
7,035 PointsStuck: Passing Factory into Controller issue
Hi Guys,
I have a feeling I have written the correct code in the challenge, but it still errors out. Others seem to have the same issue. Could someone please assist?
Here my code:
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);
}]);
<!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>
1 Answer
William Li
Courses Plus Student 26,868 PointsThe code looks good, only change to make is here.
// change this line
console.log(Course.title);
// to this
console.log(Course);
Within the controller, log the injected factory to the console using console.log.
Sidney Casagrande
7,035 PointsSidney Casagrande
7,035 PointsRight, finally got through this one. :) Yeah I do understand now reading the instructions extra carefully to log the whole Factory (not just the title).
Thanks William!
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 Pointsglad that you got through this one, yeah, it's very important to read the challenge description carefully, because lots of times the output the grader is looking for is very strict, missing a full stop, missing a space, can all result in failing to pass. Happy coding.