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) Getting Started with Angular Review: Getting Started with Angular

Nathaniel Medrano
Nathaniel Medrano
723 Points

How do I "attach" a directive to a module?

I thought nothing else went in app.js, and the directives went in a separate script file.

app.js
angular.module("foobar", []);
.directive('customDirective', fuction() {
           return {
              template: "This is a Custom Directive",
           };
});

2 Answers

Steven Parker
Steven Parker
231,275 Points

You've got some stray punctuation in the way, and some other issues:

  • you should remove the semicolon from the top line since you want to attach .directive
  • you wrote "fuction" instead of "function".
  • you callback body is different from (and more complicated than) what the challenge asks for
  • for this challenge, all the code goes in app.js

This is most curious — it looks like you have parts of task 3 there, but you have issues that would prevent passing task 1. Did you copy and paste this code from somewhere else?

Nathaniel Medrano
Nathaniel Medrano
723 Points

Thanks! It was the semi-colon after the first statement that had me stumped. And no, I just kept adding more and more since I couldn't get it to work. Rewatched the videos 3 times, and couldn't figure out how to do it if it was all on the same file.

Steven Parker
Steven Parker
231,275 Points

I see. A case of "escalating frustrations", I can sympathize. But glad you got it going! :+1: