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 trialKatrin Nitsche
23,462 PointsAngular Basics, Creating a Service code challenge
I am having some problems passing the last test. I have to add a function to the service which but I can't make it passing the test and have no idea what I do wrong.
My code:
angular.module('foobar', [])
.controller("mainCtrl"), function($scope,myService) {
$scope.TestDataService = function() {
myService.testingMyService();
}
})
.service("myService", function(callback,$http) {
this.testingMyService = function() {
console.log("This is my servicve!");
}
});
Does anybody have an idea why? I would love to continue the course. Thanks a lot Katrin
4 Answers
jesdavpet
21,489 PointsHi Katrin,
I think you have a syntax error on line 2; there shouldn't be a closing parentheses after the name "mainCtrl".
In Angular the .controller()
function should take two parameters: first the name "mainCtrl", then a callback function. The syntax error means that you're calling it with only one parameter.
Try that first, and see how it goes!
jesdavpet
21,489 PointsYou have some unused parameters/arguments... you should experiment with removing them. Your code worked fine for me after I removed the callback
argument in the anonymous function passed to .service()
!
I'm not completely sure why that worked. But, since you aren't actually using a callback, or the $http
handler here, it's harmless to remove them.
Katrin Nitsche
23,462 PointsThanks for your answer
I tried different combinations but I can't make it working.
angular.module('foobar', []) .controller("mainCtrl", function($scope, myService) { $scope.TestDataService = function() { myService.testingMyService(); } }) .service("myService", function(callback,$http) { this.testingMyService = function() { console.log("This is my service!"); } });
I have no idea what I do wrong.
Casey Jardin
3,717 Pointsangular.module('foobar', [])
.service('myService', function myService(){
this.testingMyService = function(){
console.log("This is my service!")
};
});