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 An Introduction to Directives Review: Directives

Daniel Hildreth
Daniel Hildreth
16,170 Points

Need Help With AngularJS Directives

I need help with one of the challenges in the AngularJS Basics course. It asks me to "In Javascript, how would you name a directive that could be attached as β€˜my-custom-directive’?" How do I name this, and why do I name it that way? I've watched the videos a few times over and it keeps stumping me.

Hi Daniel,

I have received and answer request for this question however unfortunately I have no knowledge of Angular JS as I have not yet done the course.

I have asked another Treehouse Member who I feel may be able to help base don what I have seen in thr forum previously and hope they can help you get to the bottom of your question :)

Craig

3 Answers

Hey Daniel,

Wish I could claim responsibility for this answer but if you check https://teamtreehouse.com/forum/angular-js-quiz-question you will find the answer you need. But basically its because elements in HTML that have dashes, i.e β€˜my-custom-directive' become camelCased in JS, i.e 'myCustomDirective'

So I guess you would just call your directive like so

.directive('myCustomDirective', function() {

}

Hope that helps!

Daniel Hildreth
Daniel Hildreth
16,170 Points

Hey thanks for your help! I can't believe it was that simple LOL! AngularJS is racking my brain!

No worries Daniel, glad I could help :-)