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 Basics (1.x) Services in Angular Create an Angular service.

Create a new service called 'myServive?'

I am stuck

angular.module('foobar', []);
.service('myService', function(){});

3 Answers

You need to chain .service onto the module definition. So, just omit your semi-colon on the first line.

angular.module('foobar', [])
  .service('myService', function(){});

By chaining with a .service, you are attaching the service to the module definition.

Jan Skovgaard
Jan Skovgaard
5,188 Points

I'm stuck on step 3/3 on this one - What is the issue here?

angular.module('foobar', []) .service('myService', function(service){ this.testingMyService = function() { console.log("This is my service!"); }; });

I keep getting the "Oops! Looks like task 1 is no longer passing". When I hit "Go to task One" and just hit "Check work" without modifying the code it passes just fine. It passed the 2nd step just fine too but on the 3rd step it's not...can't really see what the issue is? Is there a bug in the test or am I blind? :)

Jan Skovgaard
Jan Skovgaard
5,188 Points

Nevermind me! I'm blind! :D - Read the brief for task number 2 wrong. God the notion one should add a parameter called "service" to the anonymous function too. But that's clearly not what it says.

So removing the "service" argument made it pass - so the code looks like this

angular.module('foobar', []) .service('myService', function(){ this.testingMyService = function() { console.log("This is my service!"); }; });

However the validation message could have been more clear/helpful.